@@ -3127,7 +3127,7 @@ protected virtual bool GetLambdaExpression(string expression, Stack<object> stac
3127
3127
3128
3128
object result = null ;
3129
3129
3130
- if ( ( OptionCanDeclareMultiExpressionsLambdaInSimpleExpressionEvaluate || inScriptAtDeclaration )
3130
+ if ( ( OptionCanDeclareMultiExpressionsLambdaInSimpleExpressionEvaluate || inScriptAtDeclaration )
3131
3131
&& lambdaBody . StartsWith ( "{" ) && lambdaBody . EndsWith ( "}" ) )
3132
3132
{
3133
3133
result = ScriptEvaluate ( lambdaBody . Substring ( 1 , lambdaBody . Length - 2 ) ) ;
@@ -3223,7 +3223,7 @@ bool methodByNameFilter(MethodInfo m) => m.Name.Equals(func, StringComparisonFor
3223
3223
3224
3224
if ( methodInfo != null )
3225
3225
{
3226
- methodInfo = TryToCastMethodParametersToMakeItCallable ( methodInfo , modifiedArgs , genericsTypes , inferedGenericsTypes ) ;
3226
+ methodInfo = TryToCastMethodParametersToMakeItCallable ( methodInfo , modifiedArgs , genericsTypes , inferedGenericsTypes , obj ) ;
3227
3227
}
3228
3228
}
3229
3229
}
@@ -3233,7 +3233,7 @@ bool methodByNameFilter(MethodInfo m) => m.Name.Equals(func, StringComparisonFor
3233
3233
{
3234
3234
modifiedArgs = new List < object > ( args ) ;
3235
3235
3236
- methodInfo = TryToCastMethodParametersToMakeItCallable ( methodInfos [ m ] , modifiedArgs , genericsTypes , inferedGenericsTypes ) ;
3236
+ methodInfo = TryToCastMethodParametersToMakeItCallable ( methodInfos [ m ] , modifiedArgs , genericsTypes , inferedGenericsTypes , obj ) ;
3237
3237
}
3238
3238
3239
3239
if ( methodInfo != null )
@@ -3251,7 +3251,7 @@ protected virtual bool IsCastable(Type fromType, Type toType)
3251
3251
|| ( implicitCastDict . ContainsKey ( fromType ) && implicitCastDict [ fromType ] . Contains ( toType ) ) ;
3252
3252
}
3253
3253
3254
- protected virtual MethodInfo TryToCastMethodParametersToMakeItCallable ( MethodInfo methodInfoToCast , List < object > modifiedArgs , string genericsTypes , Type [ ] inferedGenericsTypes )
3254
+ protected virtual MethodInfo TryToCastMethodParametersToMakeItCallable ( MethodInfo methodInfoToCast , List < object > modifiedArgs , string genericsTypes , Type [ ] inferedGenericsTypes , object onInstance = null )
3255
3255
{
3256
3256
MethodInfo methodInfo = null ;
3257
3257
@@ -3265,7 +3265,7 @@ protected virtual MethodInfo TryToCastMethodParametersToMakeItCallable(MethodInf
3265
3265
{
3266
3266
modifiedArgs . Add ( Activator . CreateInstance ( methodInfoToCast . GetParameters ( ) . Last ( ) . ParameterType , new object [ ] { 0 } ) ) ;
3267
3267
}
3268
- else if ( methodInfoToCast . GetParameters ( ) . Length > modifiedArgs . Count )
3268
+ else if ( methodInfoToCast . GetParameters ( ) . Length > modifiedArgs . Count )
3269
3269
{
3270
3270
modifiedArgs . AddRange ( methodInfoToCast . GetParameters ( ) . Skip ( modifiedArgs . Count ) . Select ( p => p . DefaultValue ) ) ;
3271
3271
}
@@ -3341,9 +3341,10 @@ protected virtual MethodInfo TryToCastMethodParametersToMakeItCallable(MethodInf
3341
3341
{
3342
3342
try
3343
3343
{
3344
- ParameterCastEvaluationEventArg parameterCastEvaluationEventArg =
3345
- new ParameterCastEvaluationEventArg ( parameterType , modifiedArgs [ a ] ) ;
3346
- EvaluateParameterCast . Invoke ( this , parameterCastEvaluationEventArg ) ;
3344
+ ParameterCastEvaluationEventArg parameterCastEvaluationEventArg = new ParameterCastEvaluationEventArg ( methodInfo , parameterType , modifiedArgs [ a ] , a , this , onInstance ) ;
3345
+
3346
+ EvaluateParameterCast ? . Invoke ( this , parameterCastEvaluationEventArg ) ;
3347
+
3347
3348
if ( parameterCastEvaluationEventArg . FunctionModifiedArgument )
3348
3349
{
3349
3350
modifiedArgs [ a ] = parameterCastEvaluationEventArg . Argument ;
@@ -3357,7 +3358,6 @@ protected virtual MethodInfo TryToCastMethodParametersToMakeItCallable(MethodInf
3357
3358
{
3358
3359
parametersCastOK = false ;
3359
3360
}
3360
-
3361
3361
}
3362
3362
}
3363
3363
}
@@ -4407,6 +4407,22 @@ public FunctionPreEvaluationEventArg(string name, Func<string, object> evaluateF
4407
4407
/// <seealso cref="System.EventArgs" />
4408
4408
public partial class ParameterCastEvaluationEventArg : EventArgs
4409
4409
{
4410
+ /// <summary>
4411
+ /// The information of the method that it try to call
4412
+ /// </summary>
4413
+ public MethodInfo MethodInfo { get ; }
4414
+
4415
+ /// <summary>
4416
+ /// In the case of on the fly instance method definition the instance of the object on which this method (function) is called.
4417
+ /// Otherwise is set to null.
4418
+ /// </summary>
4419
+ public object This { get ; }
4420
+
4421
+ /// <summary>
4422
+ /// A reference on the current expression evaluator.
4423
+ /// </summary>
4424
+ public ExpressionEvaluator Evaluator { get ; }
4425
+
4410
4426
/// <summary>
4411
4427
/// The required type of the parameter
4412
4428
/// </summary>
@@ -4418,14 +4434,18 @@ public partial class ParameterCastEvaluationEventArg : EventArgs
4418
4434
public object OriginalArg { get ; }
4419
4435
4420
4436
/// <summary>
4421
- /// Initializes a new instance of the <see cref="ParameterCastEvaluationEventArg" /> class.
4437
+ /// Position of the argument (index from 0)
4422
4438
/// </summary>
4423
- /// <param name="parameterType">Type of the parameter.</param>
4424
- /// <param name="originalArg">The original argument.</param>
4425
- public ParameterCastEvaluationEventArg ( Type parameterType , object originalArg )
4439
+ public int ArgPosition { get ; }
4440
+
4441
+ public ParameterCastEvaluationEventArg ( MethodInfo methodInfo , Type parameterType , object originalArg , int argPosition , ExpressionEvaluator evaluator = null , object onInstance = null )
4426
4442
{
4443
+ MethodInfo = methodInfo ;
4427
4444
ParameterType = parameterType ;
4428
4445
OriginalArg = originalArg ;
4446
+ Evaluator = evaluator ;
4447
+ This = onInstance ;
4448
+ ArgPosition = argPosition ;
4429
4449
}
4430
4450
4431
4451
private object modifiedArgument ;
0 commit comments