Skip to content

Commit cb09b72

Browse files
authored
Fix the usage of ParsingConfig in some methods in the DynamicQueryableExtensions class (#883)
* Fix the usage of ParsingConfig in some methods in the DynamicQueryableExtensions class * 1 more * UT
1 parent bcd8f7b commit cb09b72

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

src/System.Linq.Dynamic.Core/DynamicQueryableExtensions.cs

+14-14
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public static bool All(this IQueryable source, ParsingConfig config, string pred
127127
Check.NotEmpty(predicate);
128128

129129
bool createParameterCtor = SupportsLinqToObjects(config, source);
130-
LambdaExpression lambda = DynamicExpressionParser.ParseLambda(createParameterCtor, source.ElementType, null, predicate, args);
130+
LambdaExpression lambda = DynamicExpressionParser.ParseLambda(config, createParameterCtor, source.ElementType, null, predicate, args);
131131

132132
return Execute<bool>(_AllPredicate, source, Expression.Quote(lambda));
133133
}
@@ -1430,7 +1430,7 @@ public static IQueryable OfType(this IQueryable source, Type type)
14301430
Check.NotNull(source);
14311431
Check.NotNull(type);
14321432

1433-
var optimized = OptimizeExpression(Expression.Call(null, _ofType.MakeGenericMethod(type), new[] { source.Expression }));
1433+
var optimized = OptimizeExpression(Expression.Call(null, _ofType.MakeGenericMethod(type), [source.Expression]));
14341434

14351435
return source.Provider.CreateQuery(optimized);
14361436
}
@@ -1547,7 +1547,7 @@ public static IOrderedQueryable OrderBy(this IQueryable source, ParsingConfig co
15471547
{
15481548
if (args.Length > 0 && args[0] != null && args[0]!.GetType().GetInterfaces().Any(i => i.Name.Contains("IComparer`1")))
15491549
{
1550-
return InternalOrderBy(source, ParsingConfig.Default, ordering, args[0]!, args);
1550+
return InternalOrderBy(source, config, ordering, args[0]!, args);
15511551
}
15521552

15531553
return InternalOrderBy(source, config, ordering, null, args);
@@ -1806,7 +1806,7 @@ public static IQueryable<TResult> Select<TResult>(this IQueryable source, Parsin
18061806
var methodCallExpression = Expression.Call(
18071807
typeof(Queryable),
18081808
nameof(Queryable.Select),
1809-
new[] { source.ElementType, typeof(TResult) },
1809+
[source.ElementType, typeof(TResult)],
18101810
source.Expression,
18111811
Expression.Quote(lambda)
18121812
);
@@ -1849,7 +1849,7 @@ public static IQueryable Select(this IQueryable source, ParsingConfig config, Ty
18491849

18501850
var optimized = OptimizeExpression(Expression.Call(
18511851
typeof(Queryable), nameof(Queryable.Select),
1852-
new[] { source.ElementType, resultType },
1852+
[source.ElementType, resultType],
18531853
source.Expression, Expression.Quote(lambda)));
18541854

18551855
return source.Provider.CreateQuery(optimized);
@@ -1905,7 +1905,7 @@ public static IQueryable SelectMany(this IQueryable source, ParsingConfig config
19051905
{
19061906
Check.NotNull(source);
19071907
Check.NotNull(config);
1908-
Check.NotNull(resultType, nameof(resultType));
1908+
Check.NotNull(resultType);
19091909
Check.NotEmpty(selector);
19101910

19111911
return SelectManyInternal(source, config, resultType, selector, args);
@@ -1980,7 +1980,7 @@ public static IQueryable<TResult> SelectMany<TResult>(this IQueryable source, Pa
19801980
Check.NotEmpty(selector);
19811981

19821982
bool createParameterCtor = config.EvaluateGroupByAtDatabase || SupportsLinqToObjects(config, source);
1983-
LambdaExpression lambda = DynamicExpressionParser.ParseLambda(createParameterCtor, source.ElementType, null, selector, args);
1983+
LambdaExpression lambda = DynamicExpressionParser.ParseLambda(config, createParameterCtor, source.ElementType, null, selector, args);
19841984

19851985
//we have to adjust to lambda to return an IEnumerable<T> instead of whatever the actual property is.
19861986
Type inputType = source.Expression.Type.GetTypeInfo().GetGenericTypeArguments()[0];
@@ -2096,12 +2096,12 @@ public static IQueryable SelectMany(
20962096
ParameterExpression xParameter = ParameterExpressionHelper.CreateParameterExpression(source.ElementType, collectionParameterName, config.RenameEmptyParameterExpressionNames);
20972097
ParameterExpression yParameter = ParameterExpressionHelper.CreateParameterExpression(sourceLambdaResultType, resultParameterName, config.RenameEmptyParameterExpressionNames);
20982098

2099-
LambdaExpression resultSelectLambda = DynamicExpressionParser.ParseLambda(config, createParameterCtor, new[] { xParameter, yParameter }, null, resultSelector, resultSelectorArgs);
2099+
LambdaExpression resultSelectLambda = DynamicExpressionParser.ParseLambda(config, createParameterCtor, [xParameter, yParameter], null, resultSelector, resultSelectorArgs);
21002100
Type resultLambdaResultType = resultSelectLambda.Body.Type;
21012101

21022102
var optimized = OptimizeExpression(Expression.Call(
21032103
typeof(Queryable), nameof(Queryable.SelectMany),
2104-
new[] { source.ElementType, sourceLambdaResultType, resultLambdaResultType },
2104+
[source.ElementType, sourceLambdaResultType, resultLambdaResultType],
21052105
source.Expression, Expression.Quote(sourceSelectLambda), Expression.Quote(resultSelectLambda))
21062106
);
21072107

@@ -2134,7 +2134,7 @@ public static dynamic Single(this IQueryable source)
21342134
{
21352135
Check.NotNull(source);
21362136

2137-
var optimized = OptimizeExpression(Expression.Call(typeof(Queryable), nameof(Queryable.Single), new[] { source.ElementType }, source.Expression));
2137+
var optimized = OptimizeExpression(Expression.Call(typeof(Queryable), nameof(Queryable.Single), [source.ElementType], source.Expression));
21382138
return source.Provider.Execute(optimized)!;
21392139
}
21402140

@@ -2205,7 +2205,7 @@ public static dynamic SingleOrDefault(this IQueryable source)
22052205
{
22062206
Check.NotNull(source);
22072207

2208-
var optimized = OptimizeExpression(Expression.Call(typeof(Queryable), nameof(Queryable.SingleOrDefault), new[] { source.ElementType }, source.Expression));
2208+
var optimized = OptimizeExpression(Expression.Call(typeof(Queryable), nameof(Queryable.SingleOrDefault), [source.ElementType], source.Expression));
22092209
return source.Provider.Execute(optimized)!;
22102210
}
22112211

@@ -2566,15 +2566,15 @@ internal static IOrderedQueryable InternalThenBy(IOrderedQueryable source, Parsi
25662566
{
25672567
queryExpr = Expression.Call(
25682568
typeof(Queryable), dynamicOrdering.MethodName,
2569-
new[] { source.ElementType, dynamicOrdering.Selector.Type },
2569+
[source.ElementType, dynamicOrdering.Selector.Type],
25702570
queryExpr, Expression.Quote(Expression.Lambda(dynamicOrdering.Selector, parameters)));
25712571
}
25722572
else
25732573
{
25742574
var comparerGenericType = typeof(IComparer<>).MakeGenericType(dynamicOrdering.Selector.Type);
25752575
queryExpr = Expression.Call(
25762576
typeof(Queryable), dynamicOrdering.MethodName,
2577-
new[] { source.ElementType, dynamicOrdering.Selector.Type },
2577+
[source.ElementType, dynamicOrdering.Selector.Type],
25782578
queryExpr, Expression.Quote(Expression.Lambda(dynamicOrdering.Selector, parameters)),
25792579
Expression.Constant(comparer, comparerGenericType));
25802580
}
@@ -2653,7 +2653,7 @@ public static IQueryable Where(this IQueryable source, ParsingConfig config, str
26532653
bool createParameterCtor = SupportsLinqToObjects(config, source);
26542654
LambdaExpression lambda = DynamicExpressionParser.ParseLambda(config, createParameterCtor, source.ElementType, null, predicate, args);
26552655

2656-
var optimized = OptimizeExpression(Expression.Call(typeof(Queryable), nameof(Queryable.Where), new[] { source.ElementType }, source.Expression, Expression.Quote(lambda)));
2656+
var optimized = OptimizeExpression(Expression.Call(typeof(Queryable), nameof(Queryable.Where), [source.ElementType], source.Expression, Expression.Quote(lambda)));
26572657
return source.Provider.CreateQuery(optimized);
26582658
}
26592659

test/System.Linq.Dynamic.Core.Tests/Parser/ExpressionParserTests.MemberAccess.cs

+7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public void ParseMemberAccess_DictionaryIndex_On_Dynamic()
2626
[Theory]
2727
[InlineData("Prop", "TestProp")]
2828
[InlineData("Field", "TestField")]
29+
[InlineData("Constant", "ConstantField")]
2930
public void Parse_StaticPropertyOrField_In_StaticClass1(string name, string value)
3031
{
3132
// Arrange
@@ -41,6 +42,7 @@ public void Parse_StaticPropertyOrField_In_StaticClass1(string name, string valu
4142
[Theory]
4243
[InlineData("Prop", "TestProp")]
4344
[InlineData("Field", "TestField")]
45+
[InlineData("Constant", "ConstantField")]
4446
public void Parse_StaticPropertyOrField_In_NonStaticClass1(string name, string value)
4547
{
4648
// Arrange
@@ -56,6 +58,7 @@ public void Parse_StaticPropertyOrField_In_NonStaticClass1(string name, string v
5658
[Theory]
5759
[InlineData("Prop", "TestProp")]
5860
[InlineData("Field", "TestField")]
61+
[InlineData("Constant", "ConstantField")]
5962
public void Parse_StaticPropertyOrField_In_NonStaticClass2(string name, string value)
6063
{
6164
// Arrange
@@ -75,6 +78,8 @@ public class StaticClassExample
7578
public static string Prop { get; set; } = "TestProp";
7679

7780
public static string Field = "TestField";
81+
82+
public const string Constant = "ConstantField";
7883
}
7984

8085
[DynamicLinqType]
@@ -83,6 +88,8 @@ public class NonStaticClassExample
8388
public static string Prop { get; set; } = "TestProp";
8489

8590
public static string Field = "TestField";
91+
92+
public const string Constant = "ConstantField";
8693
}
8794

8895
public class ProductDynamic

0 commit comments

Comments
 (0)