11/******************************************************************************************************
22 Title : ExpressionEvaluator (https://github.com/codingseb/ExpressionEvaluator)
3- Version : 1.4.19 .0
3+ Version : 1.4.19f .0
44 (if last digit (the forth) is not a zero, the version is an intermediate version and can be unstable)
55
66 Author : Coding Seb
@@ -3124,9 +3124,7 @@ protected virtual MethodInfo GetRealMethod(ref Type type, ref object obj, string
31243124 {
31253125 MethodInfo methodInfo = null ;
31263126 List < object > modifiedArgs = new List < object > ( args ) ;
3127-
3128- bool methodByNameFilter ( MethodInfo m ) => m . Name . Equals ( func , StringComparisonForCasing )
3129- && ( m . GetParameters ( ) . Length == modifiedArgs . Count || m . GetParameters ( ) . Last ( ) . IsDefined ( typeof ( ParamArrayAttribute ) , false ) ) ;
3127+ Type typeCopy = type ;
31303128
31313129 if ( OptionFluidPrefixingActive
31323130 && ( func . StartsWith ( "Fluid" , StringComparisonForCasing )
@@ -3149,74 +3147,68 @@ bool methodByNameFilter(MethodInfo m) => m.Name.Equals(func, StringComparisonFor
31493147 }
31503148 }
31513149
3150+ bool parameterValidate ( ParameterInfo p ) => p . Position >= modifiedArgs . Count
3151+ || ( testForExtention && p . Position == 0 )
3152+ || modifiedArgs [ p . Position ] == null
3153+ || p . ParameterType . IsAssignableFrom ( modifiedArgs [ p . Position ] . GetType ( ) )
3154+ || typeof ( Delegate ) . IsAssignableFrom ( p . ParameterType )
3155+ || p . IsDefined ( typeof ( ParamArrayAttribute ) )
3156+ || ( p . ParameterType . IsByRef && argsWithKeywords . Any ( a => a . Index == p . Position + ( testForExtention ? 1 : 0 ) ) ) ;
3157+
3158+
3159+ bool methodByNameFilter ( MethodInfo m ) => m . Name . Equals ( func , StringComparisonForCasing )
3160+ && ( m . GetParameters ( ) . Length == modifiedArgs . Count || m . GetParameters ( ) . Last ( ) . IsDefined ( typeof ( ParamArrayAttribute ) , false ) )
3161+ && ( typeCopy == typeof ( Enumerable ) || m . GetParameters ( ) . All ( parameterValidate ) ) ;
3162+
31523163 List < MethodInfo > methodInfos = type . GetMethods ( flag )
31533164 . Where ( methodByNameFilter )
31543165 . OrderByDescending ( m => m . GetParameters ( ) . Length )
31553166 . ToList ( ) ;
31563167
3157- if ( methodInfos . Count == 1 && ! ( methodInfos [ 0 ] . GetParameters ( ) . LastOrDefault ( ) ? . IsDefined ( typeof ( ParamArrayAttribute ) , false ) ?? false ) )
3168+ // For Linq methods that are overloaded and implement possibly lambda arguments
3169+ try
31583170 {
3159- if ( args . Contains ( null ) )
3160- {
3161- methodInfo = type . GetMethod ( func , flag ) ;
3162- }
3163- else
3171+ if ( methodInfos . Count > 1
3172+ && type == typeof ( Enumerable )
3173+ && args . Count == 2
3174+ && args [ 1 ] is InternalDelegate internalDelegate
3175+ && args [ 0 ] is IEnumerable enumerable
3176+ && enumerable . GetEnumerator ( ) is IEnumerator enumerator
3177+ && enumerator . MoveNext ( )
3178+ && methodInfos . Any ( m => m . GetParameters ( ) . Any ( p => p . ParameterType . Name . StartsWith ( "Func" ) ) ) )
31643179 {
3165- methodInfo = type . GetMethod ( func , flag , null , args . ConvertAll ( arg => arg . GetType ( ) ) . ToArray ( ) , null ) ;
3166- }
3167- }
3180+ Type lambdaResultType = internalDelegate . Invoke ( enumerator . Current ) . GetType ( ) ;
31683181
3169- if ( methodInfo != null )
3170- {
3171- methodInfo = MakeConcreteMethodIfGeneric ( methodInfo , genericsTypes , inferedGenericsTypes ) ;
3172- }
3173- else
3174- {
3175- // For Linq methods that are overloaded and implement possibly lambda arguments
3176- try
3177- {
3178- if ( methodInfos . Count > 1
3179- && type == typeof ( Enumerable )
3180- && args . Count == 2
3181- && args [ 1 ] is InternalDelegate internalDelegate
3182- && args [ 0 ] is IEnumerable enumerable
3183- && enumerable . GetEnumerator ( ) is IEnumerator enumerator
3184- && enumerator . MoveNext ( )
3185- && methodInfos . Any ( m => m . GetParameters ( ) . Any ( p => p . ParameterType . Name . StartsWith ( "Func" ) ) ) )
3182+ methodInfo = methodInfos . Find ( m =>
31863183 {
3187- Type lambdaResultType = internalDelegate . Invoke ( enumerator . Current ) . GetType ( ) ;
3184+ ParameterInfo [ ] parameterInfos = m . GetParameters ( ) ;
31883185
3189- methodInfo = methodInfos . Find ( m =>
3190- {
3191- ParameterInfo [ ] parameterInfos = m . GetParameters ( ) ;
3192-
3193- return parameterInfos . Length == 2
3194- && parameterInfos [ 1 ] . ParameterType . Name . StartsWith ( "Func" )
3195- && parameterInfos [ 1 ] . ParameterType . GenericTypeArguments is Type [ ] genericTypesArgs
3196- && genericTypesArgs . Length == 2
3197- && genericTypesArgs [ 1 ] == lambdaResultType ;
3198- } ) ;
3186+ return parameterInfos . Length == 2
3187+ && parameterInfos [ 1 ] . ParameterType . Name . StartsWith ( "Func" )
3188+ && parameterInfos [ 1 ] . ParameterType . GenericTypeArguments is Type [ ] genericTypesArgs
3189+ && genericTypesArgs . Length == 2
3190+ && genericTypesArgs [ 1 ] == lambdaResultType ;
3191+ } ) ;
31993192
3200- if ( methodInfo != null )
3201- {
3202- methodInfo = TryToCastMethodParametersToMakeItCallable ( methodInfo , modifiedArgs , genericsTypes , inferedGenericsTypes ) ;
3203- }
3193+ if ( methodInfo != null )
3194+ {
3195+ methodInfo = TryToCastMethodParametersToMakeItCallable ( methodInfo , modifiedArgs , genericsTypes , inferedGenericsTypes ) ;
32043196 }
32053197 }
3206- catch { }
3198+ }
3199+ catch { }
32073200
3208- for ( int m = 0 ; methodInfo == null && m < methodInfos . Count ; m ++ )
3209- {
3210- modifiedArgs = new List < object > ( args ) ;
3201+ for ( int m = 0 ; methodInfo == null && m < methodInfos . Count ; m ++ )
3202+ {
3203+ modifiedArgs = new List < object > ( args ) ;
32113204
3212- methodInfo = TryToCastMethodParametersToMakeItCallable ( methodInfos [ m ] , modifiedArgs , genericsTypes , inferedGenericsTypes ) ;
3213- }
3205+ methodInfo = TryToCastMethodParametersToMakeItCallable ( methodInfos [ m ] , modifiedArgs , genericsTypes , inferedGenericsTypes ) ;
3206+ }
32143207
3215- if ( methodInfo != null )
3216- {
3217- args . Clear ( ) ;
3218- args . AddRange ( modifiedArgs ) ;
3219- }
3208+ if ( methodInfo != null )
3209+ {
3210+ args . Clear ( ) ;
3211+ args . AddRange ( modifiedArgs ) ;
32203212 }
32213213
32223214 return methodInfo ;
0 commit comments