@@ -952,6 +952,12 @@ public IDictionary<string, object> Variables
952952 /// </summary>
953953 public event EventHandler < FunctionEvaluationEventArg > EvaluateFunction ;
954954
955+ /// <summary>
956+ /// Is fired when a parameter ist not the correct type for the function.
957+ /// Allow to define a custom parameter cast for the function to work on the fly.
958+ /// </summary>
959+ public event EventHandler < ParameterCastEvaluationEventArg > EvaluateParameterCast ;
960+
955961 #endregion
956962
957963 #region Constructors and overridable Inits methods
@@ -3333,7 +3339,25 @@ protected virtual MethodInfo TryToCastMethodParametersToMakeItCallable(MethodInf
33333339 }
33343340 catch
33353341 {
3336- parametersCastOK = false ;
3342+ try
3343+ {
3344+ ParameterCastEvaluationEventArg parameterCastEvaluationEventArg =
3345+ new ParameterCastEvaluationEventArg ( parameterType , modifiedArgs [ a ] ) ;
3346+ EvaluateParameterCast . Invoke ( this , parameterCastEvaluationEventArg ) ;
3347+ if ( parameterCastEvaluationEventArg . FunctionModifiedArgument )
3348+ {
3349+ modifiedArgs [ a ] = parameterCastEvaluationEventArg . Argument ;
3350+ }
3351+ else
3352+ {
3353+ parametersCastOK = false ;
3354+ }
3355+ }
3356+ catch
3357+ {
3358+ parametersCastOK = false ;
3359+ }
3360+
33373361 }
33383362 }
33393363 }
@@ -4377,5 +4401,53 @@ public FunctionPreEvaluationEventArg(string name, Func<string, object> evaluateF
43774401 public bool CancelEvaluation { get ; set ; }
43784402 }
43794403
4404+ /// <summary>
4405+ /// Class ParameterCastEvaluationEventArg.
4406+ /// Implements the <see cref="System.EventArgs" /></summary>
4407+ /// <seealso cref="System.EventArgs" />
4408+ public partial class ParameterCastEvaluationEventArg : EventArgs
4409+ {
4410+ /// <summary>
4411+ /// The required type of the parameter
4412+ /// </summary>
4413+ public Type ParameterType { get ; }
4414+
4415+ /// <summary>
4416+ /// The original argument
4417+ /// </summary>
4418+ public object OriginalArg { get ; }
4419+
4420+ /// <summary>
4421+ /// Initializes a new instance of the <see cref="ParameterCastEvaluationEventArg" /> class.
4422+ /// </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 )
4426+ {
4427+ ParameterType = parameterType ;
4428+ OriginalArg = originalArg ;
4429+ }
4430+
4431+ private object modifiedArgument ;
4432+
4433+ /// <summary>
4434+ /// To set the modified argument
4435+ /// </summary>
4436+ public object Argument
4437+ {
4438+ get { return modifiedArgument ; }
4439+ set
4440+ {
4441+ modifiedArgument = value ;
4442+ FunctionModifiedArgument = true ;
4443+ }
4444+ }
4445+
4446+ /// <summary>
4447+ /// if <c>true</c> the argument has been modified, if <c>false</c> it means that the argument can't be of the given type.
4448+ /// </summary>
4449+ public bool FunctionModifiedArgument { get ; set ; }
4450+ }
4451+
43804452 #endregion
43814453}
0 commit comments