summaryrefslogtreecommitdiff
path: root/dsa/FireBase/Query/ParameterQuery.cs
diff options
context:
space:
mode:
authoruzvkl <dennis.kobert@student.kit.edu>2019-06-11 23:05:52 +0200
committeruzvkl <dennis.kobert@student.kit.edu>2019-06-11 23:05:52 +0200
commite6181c24124d97f2fbc932b8a68311e625463156 (patch)
treec1f097c344ca266b7941c9668590b0fd35c7870a /dsa/FireBase/Query/ParameterQuery.cs
parent2490ad5d31fe2ac778ff9303776f0e91f47a2862 (diff)
Move dsa related stuff to subfolder
Diffstat (limited to 'dsa/FireBase/Query/ParameterQuery.cs')
-rw-r--r--dsa/FireBase/Query/ParameterQuery.cs43
1 files changed, 43 insertions, 0 deletions
diff --git a/dsa/FireBase/Query/ParameterQuery.cs b/dsa/FireBase/Query/ParameterQuery.cs
new file mode 100644
index 0000000..572224c
--- /dev/null
+++ b/dsa/FireBase/Query/ParameterQuery.cs
@@ -0,0 +1,43 @@
+using System;
+
+namespace Firebase.Database.Query
+{
+ /// <summary>
+ /// Represents a parameter in firebase query, e.g. "?data=foo".
+ /// </summary>
+ public abstract class ParameterQuery : FirebaseQuery
+ {
+ private readonly Func<string> parameterFactory;
+ private readonly string separator;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="ParameterQuery" /> class.
+ /// </summary>
+ /// <param name="parent"> The parent of this query. </param>
+ /// <param name="parameterFactory"> The parameter. </param>
+ /// <param name="client"> The owning client. </param>
+ protected ParameterQuery(FirebaseQuery parent, Func<string> parameterFactory, FirebaseClient client)
+ : base(parent, client)
+ {
+ this.parameterFactory = parameterFactory;
+ separator = Parent is ChildQuery ? "?" : "&";
+ }
+
+ /// <summary>
+ /// Build the url segment represented by this query.
+ /// </summary>
+ /// <param name="child"> The child. </param>
+ /// <returns> The <see cref="string" />. </returns>
+ protected override string BuildUrlSegment(FirebaseQuery child)
+ {
+ return $"{separator}{parameterFactory()}={BuildUrlParameter(child)}";
+ }
+
+ /// <summary>
+ /// The build url parameter.
+ /// </summary>
+ /// <param name="child"> The child. </param>
+ /// <returns> The <see cref="string" />. </returns>
+ protected abstract string BuildUrlParameter(FirebaseQuery child);
+ }
+} \ No newline at end of file