@@ -34,6 +34,7 @@ public class ExpressionParser
34
34
private readonly TextParser _textParser ;
35
35
private readonly NumberParser _numberParser ;
36
36
private readonly IExpressionHelper _expressionHelper ;
37
+ private readonly ConstantExpressionHelper _constantExpressionHelper ;
37
38
private readonly ITypeFinder _typeFinder ;
38
39
private readonly ITypeConverterFactory _typeConverterFactory ;
39
40
private readonly Dictionary < string , object > _internals = new ( ) ;
@@ -45,7 +46,6 @@ public class ExpressionParser
45
46
private ParameterExpression ? _root ;
46
47
private Type ? _resultType ;
47
48
private bool _createParameterCtor ;
48
- private ConstantExpressionHelper _constantExpressionHelper ;
49
49
50
50
/// <summary>
51
51
/// Gets name for the `it` field. By default this is set to the KeyWord value "it".
@@ -387,19 +387,11 @@ private Expression ParseIn()
387
387
throw ParseError ( _textParser . CurrentToken . Pos , Res . IdentifierImplementingInterfaceExpected , typeof ( IEnumerable ) ) ;
388
388
}
389
389
390
- var args = new [ ] { left } ;
391
-
392
- Expression ? nullExpressionReference = null ;
393
- if ( _methodFinder . FindMethod ( typeof ( IEnumerableSignatures ) , nameof ( IEnumerableSignatures . Contains ) , false , ref nullExpressionReference , ref args , out var containsSignature ) != 1 )
394
- {
395
- throw ParseError ( op . Pos , Res . NoApplicableAggregate , nameof ( IEnumerableSignatures . Contains ) , string . Join ( "," , args . Select ( a => a . Type . Name ) . ToArray ( ) ) ) ;
396
- }
397
-
398
390
var typeArgs = new [ ] { left . Type } ;
399
391
400
- args = new [ ] { right , left } ;
392
+ var args = new [ ] { right , left } ;
401
393
402
- accumulate = Expression . Call ( typeof ( Enumerable ) , containsSignature ! . Name , typeArgs , args ) ;
394
+ accumulate = Expression . Call ( typeof ( Enumerable ) , nameof ( Enumerable . Contains ) , typeArgs , args ) ;
403
395
}
404
396
else
405
397
{
@@ -2014,17 +2006,14 @@ private Expression ParseAsEnum(string id)
2014
2006
2015
2007
private Expression ParseEnumerable ( Expression instance , Type elementType , string methodName , int errorPos , Type ? type )
2016
2008
{
2017
- bool isQueryable = TypeHelper . FindGenericType ( typeof ( IQueryable < > ) , type ) != null ;
2018
- bool isDictionary = TypeHelper . IsDictionary ( type ) ;
2019
-
2020
2009
var oldParent = _parent ;
2021
2010
2022
2011
ParameterExpression ? outerIt = _it ;
2023
2012
ParameterExpression innerIt = ParameterExpressionHelper . CreateParameterExpression ( elementType , string . Empty , _parsingConfig . RenameEmptyParameterExpressionNames ) ;
2024
2013
2025
2014
_parent = _it ;
2026
2015
2027
- if ( methodName == "Contains" || methodName == "ContainsKey" || methodName == "Skip" || methodName == "Take" )
2016
+ if ( new [ ] { "Contains" , "ContainsKey" , "Skip" , "Take" } . Contains ( methodName ) )
2028
2017
{
2029
2018
// for any method that acts on the parent element type, we need to specify the outerIt as scope.
2030
2019
_it = outerIt ;
@@ -2039,19 +2028,14 @@ private Expression ParseEnumerable(Expression instance, Type elementType, string
2039
2028
_it = outerIt ;
2040
2029
_parent = oldParent ;
2041
2030
2042
- if ( isDictionary && _methodFinder . ContainsMethod ( typeof ( IDictionarySignatures ) , methodName , false , null , ref args ) )
2043
- {
2044
- var method = type ! . GetMethod ( methodName ) ! ;
2045
- return Expression . Call ( instance , method , args ) ;
2046
- }
2047
-
2048
- if ( ! _methodFinder . ContainsMethod ( typeof ( IEnumerableSignatures ) , methodName , false , null , ref args ) )
2031
+ if ( type != null && TypeHelper . IsDictionary ( type ) && _methodFinder . ContainsMethod ( type , methodName , false ) )
2049
2032
{
2050
- throw ParseError ( errorPos , Res . NoApplicableAggregate , methodName , string . Join ( "," , args . Select ( a => a . Type . Name ) . ToArray ( ) ) ) ;
2033
+ var dictionaryMethod = type . GetMethod ( methodName ) ! ;
2034
+ return Expression . Call ( instance , dictionaryMethod , args ) ;
2051
2035
}
2052
2036
2053
- Type callType = typeof ( Enumerable ) ;
2054
- if ( isQueryable && _methodFinder . ContainsMethod ( typeof ( IQueryableSignatures ) , methodName , false , null , ref args ) )
2037
+ var callType = typeof ( Enumerable ) ;
2038
+ if ( type != null && TypeHelper . FindGenericType ( typeof ( IQueryable < > ) , type ) != null && _methodFinder . ContainsMethod ( type , methodName ) )
2055
2039
{
2056
2040
callType = typeof ( Queryable ) ;
2057
2041
}
@@ -2073,10 +2057,14 @@ private Expression ParseEnumerable(Expression instance, Type elementType, string
2073
2057
{
2074
2058
typeArgs = new [ ] { elementType , args [ 0 ] . Type , args [ 1 ] . Type } ;
2075
2059
}
2076
- else
2060
+ else if ( args . Length == 1 )
2077
2061
{
2078
2062
typeArgs = new [ ] { elementType , args [ 0 ] . Type } ;
2079
2063
}
2064
+ else
2065
+ {
2066
+ typeArgs = new [ ] { elementType } ;
2067
+ }
2080
2068
}
2081
2069
else if ( methodName == "SelectMany" )
2082
2070
{
0 commit comments