@@ -1798,8 +1798,9 @@ private Expression ParseMemberAccess(Type? type, Expression? expression, string?
1798
1798
Expression [ ] ? args = null ;
1799
1799
1800
1800
var isStaticAccess = expression == null ;
1801
+ var isConstantString = expression is ConstantExpression { Value : string } ;
1801
1802
1802
- if ( ! isStaticAccess && TypeHelper . TryFindGenericType ( typeof ( IEnumerable < > ) , type , out var enumerableType ) )
1803
+ if ( ! isStaticAccess && ! isConstantString && TypeHelper . TryFindGenericType ( typeof ( IEnumerable < > ) , type , out var enumerableType ) )
1803
1804
{
1804
1805
var elementType = enumerableType . GetTypeInfo ( ) . GetGenericTypeArguments ( ) [ 0 ] ;
1805
1806
if ( TryParseEnumerable ( expression ! , elementType , id , errorPos , type , out args , out var enumerableExpression ) )
@@ -2042,25 +2043,32 @@ private Expression ParseAsEnumOrNestedClass(string id)
2042
2043
2043
2044
private bool TryParseEnumerable ( Expression instance , Type elementType , string methodName , int errorPos , Type ? type , out Expression [ ] ? args , [ NotNullWhen ( true ) ] out Expression ? expression )
2044
2045
{
2046
+ // Keep the current _parent.
2045
2047
var oldParent = _parent ;
2046
2048
2047
- ParameterExpression ? outerIt = _it ;
2048
- ParameterExpression innerIt = ParameterExpressionHelper . CreateParameterExpression ( elementType , string . Empty , _parsingConfig . RenameEmptyParameterExpressionNames ) ;
2049
-
2049
+ // Set the _parent to the current _it.
2050
2050
_parent = _it ;
2051
2051
2052
+ // Set the outerIt to the current _it.
2053
+ var outerIt = _it ;
2054
+
2055
+ // Create a new innerIt based on the elementType.
2056
+ var innerIt = ParameterExpressionHelper . CreateParameterExpression ( elementType , string . Empty , _parsingConfig . RenameEmptyParameterExpressionNames ) ;
2057
+
2052
2058
if ( new [ ] { "Contains" , "ContainsKey" , "Skip" , "Take" } . Contains ( methodName ) )
2053
2059
{
2054
- // for any method that acts on the parent element type, we need to specify the outerIt as scope.
2060
+ // For any method that acts on the parent element type, we need to specify the outerIt as scope.
2055
2061
_it = outerIt ;
2056
2062
}
2057
2063
else
2058
2064
{
2065
+ // Else we need to specify the innerIt as scope.
2059
2066
_it = innerIt ;
2060
2067
}
2061
2068
2062
2069
args = ParseArgumentList ( ) ;
2063
2070
2071
+ // Revert the _it and _parent to the old values.
2064
2072
_it = outerIt ;
2065
2073
_parent = oldParent ;
2066
2074
0 commit comments