diff --git a/src/System.Linq.Dynamic.Core/Parser/ExpressionParser.cs b/src/System.Linq.Dynamic.Core/Parser/ExpressionParser.cs index 2525a0d6..9a761529 100644 --- a/src/System.Linq.Dynamic.Core/Parser/ExpressionParser.cs +++ b/src/System.Linq.Dynamic.Core/Parser/ExpressionParser.cs @@ -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. @@ -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]; @@ -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; }