1
1
/******************************************************************************************************
2
2
Title : ExpressionEvaluator (https://github.com/codingseb/ExpressionEvaluator)
3
- Version : 1.4.19 .0
3
+ Version : 1.4.19f .0
4
4
(if last digit (the forth) is not a zero, the version is an intermediate version and can be unstable)
5
5
6
6
Author : Coding Seb
@@ -3124,9 +3124,7 @@ protected virtual MethodInfo GetRealMethod(ref Type type, ref object obj, string
3124
3124
{
3125
3125
MethodInfo methodInfo = null ;
3126
3126
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 ;
3130
3128
3131
3129
if ( OptionFluidPrefixingActive
3132
3130
&& ( func . StartsWith ( "Fluid" , StringComparisonForCasing )
@@ -3149,74 +3147,68 @@ bool methodByNameFilter(MethodInfo m) => m.Name.Equals(func, StringComparisonFor
3149
3147
}
3150
3148
}
3151
3149
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
+
3152
3163
List < MethodInfo > methodInfos = type . GetMethods ( flag )
3153
3164
. Where ( methodByNameFilter )
3154
3165
. OrderByDescending ( m => m . GetParameters ( ) . Length )
3155
3166
. ToList ( ) ;
3156
3167
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
3158
3170
{
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" ) ) ) )
3164
3179
{
3165
- methodInfo = type . GetMethod ( func , flag , null , args . ConvertAll ( arg => arg . GetType ( ) ) . ToArray ( ) , null ) ;
3166
- }
3167
- }
3180
+ Type lambdaResultType = internalDelegate . Invoke ( enumerator . Current ) . GetType ( ) ;
3168
3181
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 =>
3186
3183
{
3187
- Type lambdaResultType = internalDelegate . Invoke ( enumerator . Current ) . GetType ( ) ;
3184
+ ParameterInfo [ ] parameterInfos = m . GetParameters ( ) ;
3188
3185
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
+ } ) ;
3199
3192
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 ) ;
3204
3196
}
3205
3197
}
3206
- catch { }
3198
+ }
3199
+ catch { }
3207
3200
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 ) ;
3211
3204
3212
- methodInfo = TryToCastMethodParametersToMakeItCallable ( methodInfos [ m ] , modifiedArgs , genericsTypes , inferedGenericsTypes ) ;
3213
- }
3205
+ methodInfo = TryToCastMethodParametersToMakeItCallable ( methodInfos [ m ] , modifiedArgs , genericsTypes , inferedGenericsTypes ) ;
3206
+ }
3214
3207
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 ) ;
3220
3212
}
3221
3213
3222
3214
return methodInfo ;
0 commit comments