summaryrefslogtreecommitdiff
path: root/dsa/FireBase/Query/ChildQuery.cs
blob: 579bd0afa85bfbbfe24c2d61431be24f2b277a25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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;
        }
    }
}