Skip to content

Commit

Permalink
sc
Browse files Browse the repository at this point in the history
  • Loading branch information
StefH committed Dec 8, 2024
1 parent 7fcc398 commit 7874412
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/System.Linq.Dynamic.Core/Parser/ExpressionParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1820,12 +1820,11 @@ private Expression ParseMemberAccess(Type? type, Expression? expression, string?
var isStringWithStringMethod = type == typeof(string) && _methodFinder.ContainsMethod(type, id, isStaticAccess);
var isApplicableForEnumerable = !isStaticAccess && !isConstantString && !isStringWithStringMethod;

if (isApplicableForEnumerable && TypeHelper.TryFindGenericType(typeof(IEnumerable<>), type, out var enumerableType))
if (isApplicableForEnumerable &&
TypeHelper.TryFindGenericType(typeof(IEnumerable<>), type, out var enumerableType) &&
TryParseEnumerable(expression!, enumerableType, id, type, out args, out var enumerableExpression))
{
if (TryParseEnumerable(expression!, enumerableType, id, errorPos, type, out args, out var enumerableExpression))
{
return enumerableExpression;
}
return enumerableExpression;
}

// If args is not set by TryParseEnumerable (in case when the expression is not an Enumerable), do parse the argument list here.
Expand Down Expand Up @@ -2060,7 +2059,7 @@ private Expression ParseAsEnumOrNestedClass(string id)
return ParseMemberAccess(type, null, identifier);
}

private bool TryParseEnumerable(Expression instance, Type enumerableType, string methodName, int errorPos, Type? type, out Expression[]? args, [NotNullWhen(true)] out Expression? expression)
private bool TryParseEnumerable(Expression instance, Type enumerableType, string methodName, Type? type, out Expression[]? args, [NotNullWhen(true)] out Expression? expression)
{
var elementType = enumerableType.GetTypeInfo().GetGenericTypeArguments()[0];

Expand Down Expand Up @@ -2125,7 +2124,7 @@ private bool TryParseEnumerable(Expression instance, Type enumerableType, string
// #633 - For Average without any arguments, try to find the non-generic Average method on the callType for the supplied parameter type.
if (methodName == nameof(Enumerable.Average) && args.Length == 0 && _methodFinder.TryFindAverageMethod(callType, theType, out var averageMethod))
{
expression = Expression.Call(null, averageMethod, [instance]);
expression = Expression.Call(null, averageMethod, instance);
return true;
}

Expand Down

0 comments on commit 7874412

Please sign in to comment.