Skip to content

Commit affa311

Browse files
committed
#112 All(json)
1 parent 6603c8b commit affa311

1 file changed

Lines changed: 70 additions & 0 deletions

File tree

Neomaster.JsonToLinq/Application/JsonLinq.cs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,76 @@ namespace Neomaster.JsonToLinq;
88
/// </summary>
99
public static partial class JsonLinq
1010
{
11+
/// <summary>
12+
/// Determines whether all elements of a sequence satisfies a specified JSON filter.
13+
/// </summary>
14+
/// <typeparam name="TElement">The type of the elements of source.</typeparam>
15+
/// <param name="elements">An System.Collections.Generic.IEnumerable`1 whose elements to apply the JSON filter to.</param>
16+
/// <param name="filterJson">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+
/// true if every element of the source sequence passes the test in the specified JSON filter,
21+
/// or if the sequence is empty;
22+
/// otherwise, false.
23+
/// </returns>
24+
/// <exception cref="ArgumentNullException">
25+
/// The source sequence or the JSON filter is null.
26+
/// </exception>
27+
public static bool All<TElement>(
28+
this IEnumerable<TElement> elements,
29+
string filterJson,
30+
ExpressionFieldMapper fieldMapper = null,
31+
ExpressionParsingOptions options = null)
32+
{
33+
if (elements == null)
34+
{
35+
throw new ArgumentNullException(nameof(elements));
36+
}
37+
38+
if (string.IsNullOrWhiteSpace(filterJson))
39+
{
40+
throw new ArgumentNullException(nameof(filterJson));
41+
}
42+
43+
return elements.All(JsonDocument.Parse(filterJson), fieldMapper, options);
44+
}
45+
46+
/// <summary>
47+
/// Determines whether all elements of a sequence satisfies a specified JSON filter.
48+
/// </summary>
49+
/// <typeparam name="TElement">The type of the elements of source.</typeparam>
50+
/// <param name="elements">An System.Collections.Generic.IEnumerable`1 whose elements to apply the JSON filter to.</param>
51+
/// <param name="filter">JSON filter definition.</param>
52+
/// <param name="fieldMapper">Maps JSON field names to <see cref="ExpressionField"/> definitions.</param>
53+
/// <param name="options">Optional parser settings. Uses defaults if null.</param>
54+
/// <returns>
55+
/// true if every element of the source sequence passes the test in the specified JSON filter,
56+
/// or if the sequence is empty;
57+
/// otherwise, false.
58+
/// </returns>
59+
/// <exception cref="ArgumentNullException">
60+
/// The source sequence or the JSON filter is null.
61+
/// </exception>
62+
public static bool All<TElement>(
63+
this IEnumerable<TElement> elements,
64+
JsonDocument filter,
65+
ExpressionFieldMapper fieldMapper = null,
66+
ExpressionParsingOptions options = null)
67+
{
68+
if (elements == null)
69+
{
70+
throw new ArgumentNullException(nameof(elements));
71+
}
72+
73+
if (filter == null)
74+
{
75+
throw new ArgumentNullException(nameof(filter));
76+
}
77+
78+
return elements.All(ParseToFilterExpression<TElement>(filter, fieldMapper, options).Compile());
79+
}
80+
1181
/// <summary>
1282
/// Determines whether any element of a sequence satisfies a specified JSON filter.
1383
/// </summary>

0 commit comments

Comments
 (0)