@@ -1928,7 +1928,7 @@ protected virtual bool EvaluateVarOrFunc(string expression, Stack<object> stack,
1928
1928
object obj = inObject ? stack . Pop ( ) : Context ;
1929
1929
object keepObj = obj ;
1930
1930
Type objType = null ;
1931
- Type [ ] inferedGenericsTypes = obj ? . GetType ( ) . GenericTypeArguments ;
1931
+ Type [ ] inferedGenericsTypes = null ; // obj?.GetType().GenericTypeArguments;
1932
1932
ValueTypeNestingTrace valueTypeNestingTrace = null ;
1933
1933
1934
1934
if ( obj != null && TypesToBlock . Contains ( obj . GetType ( ) ) )
@@ -3424,7 +3424,54 @@ protected virtual MethodInfo TryToCastMethodParametersToMakeItCallable(MethodInf
3424
3424
3425
3425
MethodInfo oldMethodInfo = methodInfoToCast ;
3426
3426
3427
- methodInfoToCast = MakeConcreteMethodIfGeneric ( methodInfoToCast , genericsTypes , inferedGenericsTypes ) ;
3427
+ if ( methodInfoToCast . IsGenericMethod
3428
+ && methodInfoToCast . ContainsGenericParameters )
3429
+ {
3430
+ if ( ! string . IsNullOrWhiteSpace ( genericsTypes ) )
3431
+ {
3432
+ methodInfoToCast = MakeConcreteMethodIfGeneric ( methodInfoToCast , genericsTypes , inferedGenericsTypes ) ;
3433
+ }
3434
+ else
3435
+ {
3436
+ Type [ ] genericArgsTypes = methodInfoToCast . GetGenericArguments ( ) ;
3437
+ List < Type > inferedTypes = new List < Type > ( ) ;
3438
+
3439
+ for ( int t = 0 ; t < genericArgsTypes . Length ; t ++ )
3440
+ {
3441
+ if ( genericArgsTypes [ t ] . IsGenericParameter )
3442
+ {
3443
+ string name = genericArgsTypes [ t ] . Name ;
3444
+ ParameterInfo [ ] parameterInfos = methodInfoToCast . GetParameters ( ) ;
3445
+
3446
+ ParameterInfo paramsForInference = Array . Find ( parameterInfos , p => p . ParameterType . IsGenericParameter
3447
+ && p . ParameterType . Name . Equals ( name )
3448
+ && modifiedArgs . Count > p . Position
3449
+ && ! modifiedArgs [ p . Position ] . GetType ( ) . IsGenericParameter ) ;
3450
+
3451
+ if ( paramsForInference != null )
3452
+ {
3453
+ inferedTypes . Add ( modifiedArgs [ paramsForInference . Position ] . GetType ( ) ) ;
3454
+ }
3455
+ else
3456
+ {
3457
+ paramsForInference = Array . Find ( parameterInfos , p => p . ParameterType . IsGenericType
3458
+ && p . ParameterType . ContainsGenericParameters
3459
+ && p . ParameterType . GetGenericArguments ( ) . Any ( subP => subP . Name . Equals ( name ) )
3460
+ && modifiedArgs . Count > p . Position
3461
+ && ! modifiedArgs [ p . Position ] . GetType ( ) . IsGenericType ) ;
3462
+
3463
+ inferedTypes . Add ( modifiedArgs [ paramsForInference . Position ] . GetType ( ) . GetElementType ( ) ) ;
3464
+ }
3465
+ }
3466
+ else
3467
+ {
3468
+ inferedTypes . Add ( genericArgsTypes [ t ] ) ;
3469
+ }
3470
+ }
3471
+
3472
+ methodInfoToCast = MakeConcreteMethodIfGeneric ( methodInfoToCast , genericsTypes , inferedTypes . ToArray ( ) ) ;
3473
+ }
3474
+ }
3428
3475
3429
3476
bool parametersCastOK = true ;
3430
3477
0 commit comments