@@ -2064,8 +2064,8 @@ protected virtual bool EvaluateVarOrFunc(string expression, Stack<object> stack,
2064
2064
. ForEach ( outOrRefArg => AssignVariable ( outOrRefArg . VariableName , argsArray [ outOrRefArg . Index + ( isExtention ? 1 : 0 ) ] ) ) ;
2065
2065
}
2066
2066
else if ( objType . GetProperty ( varFuncName , StaticBindingFlag ) is PropertyInfo staticPropertyInfo
2067
- && ( staticPropertyInfo . PropertyType . IsSubclassOf ( typeof ( Delegate ) ) || staticPropertyInfo . PropertyType == typeof ( Delegate ) )
2068
- && staticPropertyInfo . GetValue ( obj ) is Delegate del2 )
2067
+ && ( staticPropertyInfo . PropertyType . IsSubclassOf ( typeof ( Delegate ) ) || staticPropertyInfo . PropertyType == typeof ( Delegate ) )
2068
+ && staticPropertyInfo . GetValue ( obj ) is Delegate del2 )
2069
2069
{
2070
2070
stack . Push ( del2 . DynamicInvoke ( oArgs . ToArray ( ) ) ) ;
2071
2071
}
@@ -3444,39 +3444,42 @@ protected virtual MethodInfo TryToCastMethodParametersToMakeItCallable(MethodInf
3444
3444
Type parameterType = methodInfoToCast . GetParameters ( ) [ a ] . ParameterType ;
3445
3445
string paramTypeName = parameterType . Name ;
3446
3446
3447
- if ( paramTypeName . StartsWith ( "Predicate" )
3448
- && modifiedArgs [ a ] is InternalDelegate )
3447
+ if ( modifiedArgs [ a ] is InternalDelegate internalDelegate )
3449
3448
{
3450
- InternalDelegate led = modifiedArgs [ a ] as InternalDelegate ;
3451
- modifiedArgs [ a ] = new Predicate < object > ( o => ( bool ) led ( new object [ ] { o } ) ) ;
3452
- }
3453
- else if ( paramTypeName . StartsWith ( "Func" )
3454
- && modifiedArgs [ a ] is InternalDelegate )
3455
- {
3456
- InternalDelegate led = modifiedArgs [ a ] as InternalDelegate ;
3457
- DelegateEncaps de = new DelegateEncaps ( led ) ;
3458
- MethodInfo encapsMethod = de . GetType ( )
3459
- . GetMethod ( $ "Func{ parameterType . GetGenericArguments ( ) . Length - 1 } ")
3460
- . MakeGenericMethod ( parameterType . GetGenericArguments ( ) ) ;
3461
- modifiedArgs [ a ] = Delegate . CreateDelegate ( parameterType , de , encapsMethod ) ;
3462
- }
3463
- else if ( paramTypeName . StartsWith ( "Action" )
3464
- && modifiedArgs [ a ] is InternalDelegate )
3465
- {
3466
- InternalDelegate led = modifiedArgs [ a ] as InternalDelegate ;
3467
- DelegateEncaps de = new DelegateEncaps ( led ) ;
3468
- MethodInfo encapsMethod = de . GetType ( )
3469
- . GetMethod ( $ "Action{ parameterType . GetGenericArguments ( ) . Length } ")
3470
- . MakeGenericMethod ( parameterType . GetGenericArguments ( ) ) ;
3471
- modifiedArgs [ a ] = Delegate . CreateDelegate ( parameterType , de , encapsMethod ) ;
3472
- }
3473
- else if ( paramTypeName . StartsWith ( "Converter" )
3474
- && modifiedArgs [ a ] is InternalDelegate )
3475
- {
3476
- InternalDelegate led = modifiedArgs [ a ] as InternalDelegate ;
3477
- modifiedArgs [ a ] = new Converter < object , object > ( o => led ( new object [ ] { o } ) ) ;
3449
+ if ( paramTypeName . StartsWith ( "Predicate" ) )
3450
+ {
3451
+ DelegateEncaps de = new DelegateEncaps ( internalDelegate ) ;
3452
+ MethodInfo encapsMethod = de . GetType ( )
3453
+ . GetMethod ( "Predicate" )
3454
+ . MakeGenericMethod ( parameterType . GetGenericArguments ( ) ) ;
3455
+ modifiedArgs [ a ] = Delegate . CreateDelegate ( parameterType , de , encapsMethod ) ;
3456
+ }
3457
+ else if ( paramTypeName . StartsWith ( "Func" ) )
3458
+ {
3459
+ DelegateEncaps de = new DelegateEncaps ( internalDelegate ) ;
3460
+ MethodInfo encapsMethod = de . GetType ( )
3461
+ . GetMethod ( $ "Func{ parameterType . GetGenericArguments ( ) . Length - 1 } ")
3462
+ . MakeGenericMethod ( parameterType . GetGenericArguments ( ) ) ;
3463
+ modifiedArgs [ a ] = Delegate . CreateDelegate ( parameterType , de , encapsMethod ) ;
3464
+ }
3465
+ else if ( paramTypeName . StartsWith ( "Action" ) )
3466
+ {
3467
+ DelegateEncaps de = new DelegateEncaps ( internalDelegate ) ;
3468
+ MethodInfo encapsMethod = de . GetType ( )
3469
+ . GetMethod ( $ "Action{ parameterType . GetGenericArguments ( ) . Length } ")
3470
+ . MakeGenericMethod ( parameterType . GetGenericArguments ( ) ) ;
3471
+ modifiedArgs [ a ] = Delegate . CreateDelegate ( parameterType , de , encapsMethod ) ;
3472
+ }
3473
+ else if ( paramTypeName . StartsWith ( "Converter" ) )
3474
+ {
3475
+ DelegateEncaps de = new DelegateEncaps ( internalDelegate ) ;
3476
+ MethodInfo encapsMethod = de . GetType ( )
3477
+ . GetMethod ( "Func1" )
3478
+ . MakeGenericMethod ( parameterType . GetGenericArguments ( ) ) ;
3479
+ modifiedArgs [ a ] = Delegate . CreateDelegate ( parameterType , de , encapsMethod ) ;
3480
+ }
3478
3481
}
3479
- else if ( typeof ( Delegate ) . IsAssignableFrom ( parameterType )
3482
+ else if ( typeof ( Delegate ) . IsAssignableFrom ( parameterType )
3480
3483
&& modifiedArgs [ a ] is MethodsGroupEncaps methodsGroupEncaps )
3481
3484
{
3482
3485
MethodInfo invokeMethod = parameterType . GetMethod ( "Invoke" ) ;
@@ -3490,10 +3493,10 @@ protected virtual MethodInfo TryToCastMethodParametersToMakeItCallable(MethodInf
3490
3493
{
3491
3494
delegateType = Type . GetType ( $ "System.Action`{ parametersTypes . Length } ") ;
3492
3495
}
3493
- else if ( paramTypeName . StartsWith ( "Predicate" ) )
3496
+ else if ( paramTypeName . StartsWith ( "Predicate" ) )
3494
3497
{
3495
3498
delegateType = typeof ( Predicate < > ) ;
3496
- parametersTypes = parametersTypes . Concat ( new Type [ ] { typeof ( bool ) } ) . ToArray ( ) ;
3499
+ methodInfoToCast = MakeConcreteMethodIfGeneric ( oldMethodInfo , genericsTypes , parametersTypes ) ;
3497
3500
}
3498
3501
else if ( paramTypeName . StartsWith ( "Converter" ) )
3499
3502
{
@@ -3510,7 +3513,7 @@ protected virtual MethodInfo TryToCastMethodParametersToMakeItCallable(MethodInf
3510
3513
3511
3514
modifiedArgs [ a ] = Delegate . CreateDelegate ( delegateType , methodsGroupEncaps . ContainerObject , methodForDelegate ) ;
3512
3515
3513
- if ( oldMethodInfo . IsGenericMethod &&
3516
+ if ( oldMethodInfo . IsGenericMethod &&
3514
3517
methodInfoToCast . GetGenericArguments ( ) . Length == parametersTypes . Length &&
3515
3518
! methodInfoToCast . GetGenericArguments ( ) . SequenceEqual ( parametersTypes ) &&
3516
3519
string . IsNullOrWhiteSpace ( genericsTypes ) )
@@ -3543,6 +3546,15 @@ protected virtual MethodInfo TryToCastMethodParametersToMakeItCallable(MethodInf
3543
3546
if ( ! parameterType . GetElementType ( ) . IsAssignableFrom ( modifiedArgs [ a ] . GetType ( ) ) )
3544
3547
modifiedArgs [ a ] = Convert . ChangeType ( modifiedArgs [ a ] , parameterType . GetElementType ( ) ) ;
3545
3548
}
3549
+ else if ( modifiedArgs [ a ] . GetType ( ) . IsArray
3550
+ && typeof ( IEnumerable ) . IsAssignableFrom ( parameterType )
3551
+ && oldMethodInfo . IsGenericMethod
3552
+ && string . IsNullOrWhiteSpace ( genericsTypes )
3553
+ && methodInfoToCast . GetGenericArguments ( ) . Length == 1
3554
+ && ! methodInfoToCast . GetGenericArguments ( ) [ 0 ] . Equals ( modifiedArgs [ a ] . GetType ( ) . GetElementType ( ) ) )
3555
+ {
3556
+ methodInfoToCast = MakeConcreteMethodIfGeneric ( oldMethodInfo , genericsTypes , new Type [ ] { modifiedArgs [ a ] . GetType ( ) . GetElementType ( ) } ) ;
3557
+ }
3546
3558
else
3547
3559
{
3548
3560
modifiedArgs [ a ] = Convert . ChangeType ( modifiedArgs [ a ] , parameterType ) ;
@@ -4029,6 +4041,11 @@ public void Action0()
4029
4041
lambda ( ) ;
4030
4042
}
4031
4043
4044
+ public bool Predicate < T1 > ( T1 arg1 )
4045
+ {
4046
+ return ( bool ) lambda ( arg1 ) ;
4047
+ }
4048
+
4032
4049
public void Action1 < T1 > ( T1 arg1 )
4033
4050
{
4034
4051
lambda ( arg1 ) ;
0 commit comments