From e6181c24124d97f2fbc932b8a68311e625463156 Mon Sep 17 00:00:00 2001 From: uzvkl Date: Tue, 11 Jun 2019 23:05:52 +0200 Subject: Move dsa related stuff to subfolder --- dsa/FireBase/Query/FilterQuery.cs | 77 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 dsa/FireBase/Query/FilterQuery.cs (limited to 'dsa/FireBase/Query/FilterQuery.cs') diff --git a/dsa/FireBase/Query/FilterQuery.cs b/dsa/FireBase/Query/FilterQuery.cs new file mode 100644 index 0000000..3434d1d --- /dev/null +++ b/dsa/FireBase/Query/FilterQuery.cs @@ -0,0 +1,77 @@ +using System; +using System.Globalization; + +namespace Firebase.Database.Query +{ + /// + /// Represents a firebase filtering query, e.g. "?LimitToLast=10". + /// + public class FilterQuery : ParameterQuery + { + private readonly Func boolValueFactory; + private readonly Func doubleValueFactory; + private readonly Func valueFactory; + + /// + /// Initializes a new instance of the class. + /// + /// The parent. + /// The filter. + /// The value for filter. + /// The owning client. + public FilterQuery(FirebaseQuery parent, Func filterFactory, Func valueFactory, + FirebaseClient client) + : base(parent, filterFactory, client) + { + this.valueFactory = valueFactory; + } + + /// + /// Initializes a new instance of the class. + /// + /// The parent. + /// The filter. + /// The value for filter. + /// The owning client. + public FilterQuery(FirebaseQuery parent, Func filterFactory, Func valueFactory, + FirebaseClient client) + : base(parent, filterFactory, client) + { + doubleValueFactory = valueFactory; + } + + /// + /// Initializes a new instance of the class. + /// + /// The parent. + /// The filter. + /// The value for filter. + /// The owning client. + public FilterQuery(FirebaseQuery parent, Func filterFactory, Func valueFactory, + FirebaseClient client) + : base(parent, filterFactory, client) + { + boolValueFactory = valueFactory; + } + + /// + /// The build url parameter. + /// + /// The child. + /// Url parameter part of the resulting path. + protected override string BuildUrlParameter(FirebaseQuery child) + { + if (valueFactory != null) + { + if (valueFactory() == null) return "null"; + return $"\"{valueFactory()}\""; + } + + if (doubleValueFactory != null) + return doubleValueFactory().ToString(CultureInfo.InvariantCulture); + if (boolValueFactory != null) return $"{boolValueFactory().ToString().ToLower()}"; + + return string.Empty; + } + } +} \ No newline at end of file -- cgit v1.2.3-54-g00ecf