/** * Parse the dotNotation of the RHS. */ public static List <IPathElement> ParseDotNotationRHS(string dotNotation) { string fixedNotation = SpecStringParser.FixLeadingBracketSugar(dotNotation); List <string> pathStrs = SpecStringParser.ParseDotNotation(new List <string>(), fixedNotation.GetEnumerator(), dotNotation); return(ParseList(pathStrs, dotNotation)); }
public Filtr(JToken spec) { if (spec == null) { throw new SpecException("Filtr expected a spec of Map type, got 'null'."); } if (!(spec is JObject dic)) { throw new SpecException("Filtr expected a spec of Map type, got " + spec.GetType().Name); } _rootSpec = new FiltrCompositeSpec(null); foreach (var kv in dic) { List <string> pathStrs = SpecStringParser.ParseDotNotation(new List <string>(), kv.Key.GetEnumerator(), kv.Key); var parentSpec = _rootSpec; foreach (var pathStr in pathStrs) { var pathElement = RemovrSpec.Parse(pathStr); if (!parentSpec.Children.TryGetValue(pathElement.RawKey, out var childSpec)) { childSpec = new FiltrCompositeSpec(pathElement); parentSpec.Children.Add(pathElement.RawKey, childSpec); } parentSpec = childSpec; } if (!(kv.Value is JObject filterSpec)) { throw new SpecException($"Filtr object filter specification must be a JSON object (found {kv.Value.Type})"); } var propFilters = new List <KeyValuePair <string, JToken> >(); foreach (var filterKv in filterSpec) { if (filterKv.Value.Type == JTokenType.Array || filterKv.Value.Type == JTokenType.Object) { throw new SpecException($"Filter object filter specification must be a simple JSON value (string, number or null)"); } propFilters.Add(new KeyValuePair <string, JToken>(filterKv.Key, filterKv.Value)); } parentSpec.Filters.Add(new FiltrLeafSpec(propFilters.AsReadOnly())); } }