@@ -3127,7 +3127,7 @@ protected virtual bool GetLambdaExpression(string expression, Stack<object> stac
31273127
31283128 object result = null ;
31293129
3130- if ( ( OptionCanDeclareMultiExpressionsLambdaInSimpleExpressionEvaluate || inScriptAtDeclaration )
3130+ if ( ( OptionCanDeclareMultiExpressionsLambdaInSimpleExpressionEvaluate || inScriptAtDeclaration )
31313131 && lambdaBody . StartsWith ( "{" ) && lambdaBody . EndsWith ( "}" ) )
31323132 {
31333133 result = ScriptEvaluate ( lambdaBody . Substring ( 1 , lambdaBody . Length - 2 ) ) ;
@@ -3223,7 +3223,7 @@ bool methodByNameFilter(MethodInfo m) => m.Name.Equals(func, StringComparisonFor
32233223
32243224 if ( methodInfo != null )
32253225 {
3226- methodInfo = TryToCastMethodParametersToMakeItCallable ( methodInfo , modifiedArgs , genericsTypes , inferedGenericsTypes ) ;
3226+ methodInfo = TryToCastMethodParametersToMakeItCallable ( methodInfo , modifiedArgs , genericsTypes , inferedGenericsTypes , obj ) ;
32273227 }
32283228 }
32293229 }
@@ -3233,7 +3233,7 @@ bool methodByNameFilter(MethodInfo m) => m.Name.Equals(func, StringComparisonFor
32333233 {
32343234 modifiedArgs = new List < object > ( args ) ;
32353235
3236- methodInfo = TryToCastMethodParametersToMakeItCallable ( methodInfos [ m ] , modifiedArgs , genericsTypes , inferedGenericsTypes ) ;
3236+ methodInfo = TryToCastMethodParametersToMakeItCallable ( methodInfos [ m ] , modifiedArgs , genericsTypes , inferedGenericsTypes , obj ) ;
32373237 }
32383238
32393239 if ( methodInfo != null )
@@ -3251,7 +3251,7 @@ protected virtual bool IsCastable(Type fromType, Type toType)
32513251 || ( implicitCastDict . ContainsKey ( fromType ) && implicitCastDict [ fromType ] . Contains ( toType ) ) ;
32523252 }
32533253
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 )
32553255 {
32563256 MethodInfo methodInfo = null ;
32573257
@@ -3265,7 +3265,7 @@ protected virtual MethodInfo TryToCastMethodParametersToMakeItCallable(MethodInf
32653265 {
32663266 modifiedArgs . Add ( Activator . CreateInstance ( methodInfoToCast . GetParameters ( ) . Last ( ) . ParameterType , new object [ ] { 0 } ) ) ;
32673267 }
3268- else if ( methodInfoToCast . GetParameters ( ) . Length > modifiedArgs . Count )
3268+ else if ( methodInfoToCast . GetParameters ( ) . Length > modifiedArgs . Count )
32693269 {
32703270 modifiedArgs . AddRange ( methodInfoToCast . GetParameters ( ) . Skip ( modifiedArgs . Count ) . Select ( p => p . DefaultValue ) ) ;
32713271 }
@@ -3341,9 +3341,10 @@ protected virtual MethodInfo TryToCastMethodParametersToMakeItCallable(MethodInf
33413341 {
33423342 try
33433343 {
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+
33473348 if ( parameterCastEvaluationEventArg . FunctionModifiedArgument )
33483349 {
33493350 modifiedArgs [ a ] = parameterCastEvaluationEventArg . Argument ;
@@ -3357,7 +3358,6 @@ protected virtual MethodInfo TryToCastMethodParametersToMakeItCallable(MethodInf
33573358 {
33583359 parametersCastOK = false ;
33593360 }
3360-
33613361 }
33623362 }
33633363 }
@@ -4407,6 +4407,22 @@ public FunctionPreEvaluationEventArg(string name, Func<string, object> evaluateF
44074407 /// <seealso cref="System.EventArgs" />
44084408 public partial class ParameterCastEvaluationEventArg : EventArgs
44094409 {
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+
44104426 /// <summary>
44114427 /// The required type of the parameter
44124428 /// </summary>
@@ -4418,14 +4434,18 @@ public partial class ParameterCastEvaluationEventArg : EventArgs
44184434 public object OriginalArg { get ; }
44194435
44204436 /// <summary>
4421- /// Initializes a new instance of the <see cref="ParameterCastEvaluationEventArg" /> class.
4437+ /// Position of the argument (index from 0)
44224438 /// </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 )
44264442 {
4443+ MethodInfo = methodInfo ;
44274444 ParameterType = parameterType ;
44284445 OriginalArg = originalArg ;
4446+ Evaluator = evaluator ;
4447+ This = onInstance ;
4448+ ArgPosition = argPosition ;
44294449 }
44304450
44314451 private object modifiedArgument ;
0 commit comments