summaryrefslogtreecommitdiff
path: root/FireBase/Query/ParameterQuery.cs
diff options
context:
space:
mode:
authorTrueDoctor <d-kobert@web.de>2018-09-29 16:51:26 +0200
committerTrueDoctor <d-kobert@web.de>2018-09-29 16:51:26 +0200
commitde0f076ef9ff546c9a90513259ad6c42cd2224b3 (patch)
tree995d766417fd2093d7950694ef17f3c84b7f1042 /FireBase/Query/ParameterQuery.cs
parent04912687127303fd270b61f131cf68fd4aaae956 (diff)
added firebase api
Diffstat (limited to 'FireBase/Query/ParameterQuery.cs')
-rw-r--r--FireBase/Query/ParameterQuery.cs43
1 files changed, 43 insertions, 0 deletions
diff --git a/FireBase/Query/ParameterQuery.cs b/FireBase/Query/ParameterQuery.cs
new file mode 100644
index 0000000..e3d9717
--- /dev/null
+++ b/FireBase/Query/ParameterQuery.cs
@@ -0,0 +1,43 @@
+namespace Firebase.Database.Query
+{
+ using System;
+
+ /// <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;
+ this.separator = (this.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 $"{this.separator}{this.parameterFactory()}={this.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);
+ }
+}