diff options
author | TrueKuehli <rctcoaster2000@hotmail.de> | 2018-09-29 17:19:43 +0200 |
---|---|---|
committer | TrueKuehli <rctcoaster2000@hotmail.de> | 2018-09-29 17:19:43 +0200 |
commit | b83fc90abacc73262e0f8404cebadf6d64eb10ae (patch) | |
tree | d63b921c9bcdf8d381fc02ecfb0a1dd425ebb561 /FireBase/Query/ChildQuery.cs | |
parent | 586d564f3c4c509c1aae931331e96f0382178f80 (diff) | |
parent | 680967aee589e4a8d277044b204de07cbe32f41e (diff) |
Merge branch 'WebApi' of https://github.com/TrueDoctor/DiscoBot into WebApi
Merged the stuffs
Diffstat (limited to 'FireBase/Query/ChildQuery.cs')
-rw-r--r-- | FireBase/Query/ChildQuery.cs | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/FireBase/Query/ChildQuery.cs b/FireBase/Query/ChildQuery.cs new file mode 100644 index 0000000..1696ea8 --- /dev/null +++ b/FireBase/Query/ChildQuery.cs @@ -0,0 +1,56 @@ +namespace Firebase.Database.Query +{ + using System; + + /// <summary> + /// Firebase query which references the child of current node. + /// </summary> + public class ChildQuery : FirebaseQuery + { + private readonly Func<string> pathFactory; + + /// <summary> + /// Initializes a new instance of the <see cref="ChildQuery"/> class. + /// </summary> + /// <param name="parent"> The parent. </param> + /// <param name="pathFactory"> The path to the child node. </param> + /// <param name="client"> The owner. </param> + public ChildQuery(FirebaseQuery parent, Func<string> pathFactory, FirebaseClient client) + : base(parent, client) + { + this.pathFactory = pathFactory; + } + + /// <summary> + /// Initializes a new instance of the <see cref="ChildQuery"/> class. + /// </summary> + /// <param name="client"> The client. </param> + /// <param name="pathFactory"> The path to the child node. </param> + public ChildQuery(FirebaseClient client, Func<string> pathFactory) + : this(null, pathFactory, client) + { + } + + /// <summary> + /// Build the url segment of this child. + /// </summary> + /// <param name="child"> The child of this child. </param> + /// <returns> The <see cref="string"/>. </returns> + protected override string BuildUrlSegment(FirebaseQuery child) + { + var s = this.pathFactory(); + + if (s != string.Empty && !s.EndsWith("/")) + { + s += '/'; + } + + if (!(child is ChildQuery)) + { + return s + ".json"; + } + + return s; + } + } +} |