Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions src/System.Linq.Dynamic.Core/DynamicQueryableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
Check.NotEmpty(predicate);

bool createParameterCtor = SupportsLinqToObjects(config, source);
LambdaExpression lambda = DynamicExpressionParser.ParseLambda(createParameterCtor, source.ElementType, null, predicate, args);
LambdaExpression lambda = DynamicExpressionParser.ParseLambda(config, createParameterCtor, source.ElementType, null, predicate, args);

return Execute<bool>(_AllPredicate, source, Expression.Quote(lambda));
}
Expand Down Expand Up @@ -1430,7 +1430,7 @@
Check.NotNull(source);
Check.NotNull(type);

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

return source.Provider.CreateQuery(optimized);
}
Expand Down Expand Up @@ -1547,7 +1547,7 @@
{
if (args.Length > 0 && args[0] != null && args[0]!.GetType().GetInterfaces().Any(i => i.Name.Contains("IComparer`1")))
{
return InternalOrderBy(source, ParsingConfig.Default, ordering, args[0]!, args);
return InternalOrderBy(source, config, ordering, args[0]!, args);
}

return InternalOrderBy(source, config, ordering, null, args);
Expand Down Expand Up @@ -1806,7 +1806,7 @@
var methodCallExpression = Expression.Call(
typeof(Queryable),
nameof(Queryable.Select),
new[] { source.ElementType, typeof(TResult) },
[source.ElementType, typeof(TResult)],
source.Expression,
Expression.Quote(lambda)
);
Expand Down Expand Up @@ -1849,7 +1849,7 @@

var optimized = OptimizeExpression(Expression.Call(
typeof(Queryable), nameof(Queryable.Select),
new[] { source.ElementType, resultType },
[source.ElementType, resultType],
source.Expression, Expression.Quote(lambda)));

return source.Provider.CreateQuery(optimized);
Expand Down Expand Up @@ -1905,7 +1905,7 @@
{
Check.NotNull(source);
Check.NotNull(config);
Check.NotNull(resultType, nameof(resultType));
Check.NotNull(resultType);
Check.NotEmpty(selector);

return SelectManyInternal(source, config, resultType, selector, args);
Expand Down Expand Up @@ -1980,7 +1980,7 @@
Check.NotEmpty(selector);

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

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

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

var optimized = OptimizeExpression(Expression.Call(
typeof(Queryable), nameof(Queryable.SelectMany),
new[] { source.ElementType, sourceLambdaResultType, resultLambdaResultType },
[source.ElementType, sourceLambdaResultType, resultLambdaResultType],
source.Expression, Expression.Quote(sourceSelectLambda), Expression.Quote(resultSelectLambda))
);

Expand All @@ -2111,7 +2111,7 @@
/// <inheritdoc cref="SelectMany(IQueryable, ParsingConfig, string, string, string, string, object[], object[])"/>
public static IQueryable SelectMany(this IQueryable source, string collectionSelector, string resultSelector, string collectionParameterName, string resultParameterName, object?[]? collectionSelectorArgs = null, params object?[]? resultSelectorArgs)
{
return SelectMany(source, ParsingConfig.Default, collectionSelector, resultSelector, collectionParameterName, resultParameterName, collectionSelectorArgs, resultSelectorArgs);

Check warning on line 2114 in src/System.Linq.Dynamic.Core/DynamicQueryableExtensions.cs

View workflow job for this annotation

GitHub Actions / Windows: Build and Tests

Argument of type 'object?[]' cannot be used for parameter 'resultSelectorArgs' of type 'object[]' in 'IQueryable DynamicQueryableExtensions.SelectMany(IQueryable source, ParsingConfig config, string collectionSelector, string resultSelector, string collectionParameterName, string resultParameterName, object?[]? collectionSelectorArgs = null, params object[]? resultSelectorArgs)' due to differences in the nullability of reference types.

Check warning on line 2114 in src/System.Linq.Dynamic.Core/DynamicQueryableExtensions.cs

View workflow job for this annotation

GitHub Actions / Linux: Build and Tests

Argument of type 'object?[]' cannot be used for parameter 'resultSelectorArgs' of type 'object[]' in 'IQueryable DynamicQueryableExtensions.SelectMany(IQueryable source, ParsingConfig config, string collectionSelector, string resultSelector, string collectionParameterName, string resultParameterName, object?[]? collectionSelectorArgs = null, params object[]? resultSelectorArgs)' due to differences in the nullability of reference types.
}

#endregion SelectMany
Expand All @@ -2134,7 +2134,7 @@
{
Check.NotNull(source);

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

Expand Down Expand Up @@ -2205,7 +2205,7 @@
{
Check.NotNull(source);

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

Expand Down Expand Up @@ -2566,15 +2566,15 @@
{
queryExpr = Expression.Call(
typeof(Queryable), dynamicOrdering.MethodName,
new[] { source.ElementType, dynamicOrdering.Selector.Type },
[source.ElementType, dynamicOrdering.Selector.Type],
queryExpr, Expression.Quote(Expression.Lambda(dynamicOrdering.Selector, parameters)));
}
else
{
var comparerGenericType = typeof(IComparer<>).MakeGenericType(dynamicOrdering.Selector.Type);
queryExpr = Expression.Call(
typeof(Queryable), dynamicOrdering.MethodName,
new[] { source.ElementType, dynamicOrdering.Selector.Type },
[source.ElementType, dynamicOrdering.Selector.Type],
queryExpr, Expression.Quote(Expression.Lambda(dynamicOrdering.Selector, parameters)),
Expression.Constant(comparer, comparerGenericType));
}
Expand Down Expand Up @@ -2653,7 +2653,7 @@
bool createParameterCtor = SupportsLinqToObjects(config, source);
LambdaExpression lambda = DynamicExpressionParser.ParseLambda(config, createParameterCtor, source.ElementType, null, predicate, args);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public void ParseMemberAccess_DictionaryIndex_On_Dynamic()
[Theory]
[InlineData("Prop", "TestProp")]
[InlineData("Field", "TestField")]
[InlineData("Constant", "ConstantField")]
public void Parse_StaticPropertyOrField_In_StaticClass1(string name, string value)
{
// Arrange
Expand All @@ -41,6 +42,7 @@ public void Parse_StaticPropertyOrField_In_StaticClass1(string name, string valu
[Theory]
[InlineData("Prop", "TestProp")]
[InlineData("Field", "TestField")]
[InlineData("Constant", "ConstantField")]
public void Parse_StaticPropertyOrField_In_NonStaticClass1(string name, string value)
{
// Arrange
Expand All @@ -56,6 +58,7 @@ public void Parse_StaticPropertyOrField_In_NonStaticClass1(string name, string v
[Theory]
[InlineData("Prop", "TestProp")]
[InlineData("Field", "TestField")]
[InlineData("Constant", "ConstantField")]
public void Parse_StaticPropertyOrField_In_NonStaticClass2(string name, string value)
{
// Arrange
Expand All @@ -75,6 +78,8 @@ public class StaticClassExample
public static string Prop { get; set; } = "TestProp";

public static string Field = "TestField";

public const string Constant = "ConstantField";
}

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

public static string Field = "TestField";

public const string Constant = "ConstantField";
}

public class ProductDynamic
Expand Down
Loading