diff options
author | Dennis Kobert <d-kobert@web.de> | 2019-06-11 23:38:13 +0200 |
---|---|---|
committer | Dennis Kobert <d-kobert@web.de> | 2019-06-11 23:38:13 +0200 |
commit | 2fa4a0e50ebfc97059c8b84dbd17e79f9afc8a8d (patch) | |
tree | c3b34ccb2737e347a73768536895cbbaab13cc01 /dsa/FireBase/Query/ChildQuery.cs | |
parent | ec991104f56e90d7bb2878da2fe6ed4e585dfc46 (diff) | |
parent | af74efccf8d21e6151022b71f3cacd3fa83024ee (diff) |
Merge branch 'rework-backend'
Diffstat (limited to 'dsa/FireBase/Query/ChildQuery.cs')
-rw-r--r-- | dsa/FireBase/Query/ChildQuery.cs | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/dsa/FireBase/Query/ChildQuery.cs b/dsa/FireBase/Query/ChildQuery.cs new file mode 100644 index 0000000..014fe09 --- /dev/null +++ b/dsa/FireBase/Query/ChildQuery.cs @@ -0,0 +1,50 @@ +using System; + +namespace Firebase.Database.Query +{ + /// <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 = pathFactory(); + + if (s != string.Empty && !s.EndsWith("/")) s += '/'; + + if (!(child is ChildQuery)) return s + ".json"; + + return s; + } + } +}
\ No newline at end of file |