@@ -8,6 +8,48 @@ namespace Neomaster.JsonToLinq;
88/// </summary>
99public static class JsonLinq
1010{
11+ /// <summary>
12+ /// Filters a sequence of values based on a JSON filter definition.
13+ /// </summary>
14+ /// <typeparam name="TElement">Type of elements to filter.</typeparam>
15+ /// <param name="elements">An System.Collections.Generic.IEnumerable`1 to filter.</param>
16+ /// <param name="json">JSON filter definition.</param>
17+ /// <param name="fieldMapper">Maps JSON field names to <see cref="ExpressionField"/> definitions.</param>
18+ /// <param name="options">Optional parser settings. Uses defaults if null.</param>
19+ /// <returns>
20+ /// An System.Collections.Generic.IEnumerable`1
21+ /// that contains elements from the input sequence that satisfy the condition.
22+ /// </returns>
23+ public static IEnumerable < TElement > Where < TElement > (
24+ this IEnumerable < TElement > elements ,
25+ string json ,
26+ ExpressionFieldMapper fieldMapper = null ,
27+ ExpressionParsingOptions options = null )
28+ {
29+ return elements . Where ( JsonDocument . Parse ( json ) , fieldMapper , options ) ;
30+ }
31+
32+ /// <summary>
33+ /// Filters a sequence of values based on a JSON filter definition.
34+ /// </summary>
35+ /// <typeparam name="TElement">Type of elements to filter.</typeparam>
36+ /// <param name="elements">An System.Collections.Generic.IEnumerable`1 to filter.</param>
37+ /// <param name="doc">JSON filter definition.</param>
38+ /// <param name="fieldMapper">Maps JSON field names to <see cref="ExpressionField"/> definitions.</param>
39+ /// <param name="options">Optional parser settings. Uses defaults if null.</param>
40+ /// <returns>
41+ /// An System.Collections.Generic.IEnumerable`1
42+ /// that contains elements from the input sequence that satisfy the condition.
43+ /// </returns>
44+ public static IEnumerable < TElement > Where < TElement > (
45+ this IEnumerable < TElement > elements ,
46+ JsonDocument doc ,
47+ ExpressionFieldMapper fieldMapper = null ,
48+ ExpressionParsingOptions options = null )
49+ {
50+ return elements . Where ( ParseToFilterExpression < TElement > ( doc , fieldMapper , options ) . Compile ( ) ) ;
51+ }
52+
1153 /// <summary>
1254 /// Parses a JSON document into a LINQ expression filter for <typeparamref name="T"/>.
1355 /// </summary>
0 commit comments