@@ -918,7 +918,7 @@ protected virtual BindingFlags StaticBindingFlag
918
918
private int evaluationStackCount ;
919
919
920
920
/// <summary>
921
- /// The Values of the variable use in the expressions
921
+ /// The values of the variable use in the expressions
922
922
/// </summary>
923
923
public IDictionary < string , object > Variables
924
924
{
@@ -927,34 +927,47 @@ public IDictionary<string, object> Variables
927
927
}
928
928
929
929
/// <summary>
930
- /// Is Fired before a variable, field or property resolution.
930
+ /// Is fired before a variable, field or property resolution.
931
931
/// Allow to define a variable and the corresponding value on the fly.
932
932
/// Allow also to cancel the evaluation of this variable (consider it does'nt exists)
933
933
/// </summary>
934
934
public event EventHandler < VariablePreEvaluationEventArg > PreEvaluateVariable ;
935
935
936
936
/// <summary>
937
- /// Is Fired before a function or method resolution.
937
+ /// Is fired before a function or method resolution.
938
938
/// Allow to define a function or method and the corresponding value on the fly.
939
939
/// Allow also to cancel the evaluation of this function (consider it does'nt exists)
940
940
/// </summary>
941
941
public event EventHandler < FunctionPreEvaluationEventArg > PreEvaluateFunction ;
942
942
943
943
/// <summary>
944
- /// Is Fired if no variable, field or property were found
944
+ /// Is fired before a indexing resolution.
945
+ /// Allow to define an indexing and the corresponding value on the fly.
946
+ /// Allow also to cancel the evaluation of this indexing (consider it does'nt exists)
947
+ /// </summary>
948
+ public event EventHandler < IndexingPreEvaluationEventArg > PreEvaluateIndexing ;
949
+
950
+ /// <summary>
951
+ /// Is fired if no variable, field or property were found
945
952
/// Allow to define a variable and the corresponding value on the fly.
946
953
/// </summary>
947
954
public event EventHandler < VariableEvaluationEventArg > EvaluateVariable ;
948
955
949
956
/// <summary>
950
- /// Is Fired if no function or method when were found.
957
+ /// Is fired if no function or method were found.
951
958
/// Allow to define a function or method and the corresponding value on the fly.
952
959
/// </summary>
953
960
public event EventHandler < FunctionEvaluationEventArg > EvaluateFunction ;
954
961
955
962
/// <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.
963
+ /// Is fired if no indexing were found.
964
+ /// Allow to define an indexing and the corresponding value on the fly.
965
+ /// </summary>
966
+ public event EventHandler < IndexingEvaluationEventArg > EvaluateIndexing ;
967
+
968
+ /// <summary>
969
+ /// Is fired when a parameter is not of the correct type for the function.
970
+ /// Allow to define a custom parameter cast to make the function call work on the fly.
958
971
/// </summary>
959
972
public event EventHandler < ParameterCastEvaluationEventArg > EvaluateParameterCast ;
960
973
@@ -1541,7 +1554,7 @@ public T Evaluate<T>(string expression)
1541
1554
EvaluateOperators ,
1542
1555
EvaluateChar ,
1543
1556
EvaluateParenthis ,
1544
- EvaluateIndexing ,
1557
+ EvaluateIndexingOperator ,
1545
1558
EvaluateString ,
1546
1559
EvaluateTernaryConditionalOperator ,
1547
1560
} ) ;
@@ -1909,7 +1922,7 @@ protected virtual bool EvaluateVarOrFunc(string expression, Stack<object> stack,
1909
1922
}
1910
1923
else
1911
1924
{
1912
- FunctionPreEvaluationEventArg functionPreEvaluationEventArg = new FunctionPreEvaluationEventArg ( varFuncName , Evaluate , funcArgs , this , obj , genericsTypes , GetConcreteTypes ) ;
1925
+ FunctionPreEvaluationEventArg functionPreEvaluationEventArg = new FunctionPreEvaluationEventArg ( varFuncName , funcArgs , this , obj , genericsTypes , GetConcreteTypes ) ;
1913
1926
1914
1927
PreEvaluateFunction ? . Invoke ( this , functionPreEvaluationEventArg ) ;
1915
1928
@@ -2025,7 +2038,7 @@ protected virtual bool EvaluateVarOrFunc(string expression, Stack<object> stack,
2025
2038
}
2026
2039
else
2027
2040
{
2028
- FunctionEvaluationEventArg functionEvaluationEventArg = new FunctionEvaluationEventArg ( varFuncName , Evaluate , funcArgs , this , obj ?? keepObj , genericsTypes , GetConcreteTypes ) ;
2041
+ FunctionEvaluationEventArg functionEvaluationEventArg = new FunctionEvaluationEventArg ( varFuncName , funcArgs , this , obj ?? keepObj , genericsTypes , GetConcreteTypes ) ;
2029
2042
2030
2043
EvaluateFunction ? . Invoke ( this , functionEvaluationEventArg ) ;
2031
2044
@@ -2089,7 +2102,7 @@ where method.GetParameters()[0].ParameterType == objType // static extMethod(thi
2089
2102
}
2090
2103
else
2091
2104
{
2092
- FunctionPreEvaluationEventArg functionPreEvaluationEventArg = new FunctionPreEvaluationEventArg ( varFuncName , Evaluate , funcArgs , this , null , genericsTypes , GetConcreteTypes ) ;
2105
+ FunctionPreEvaluationEventArg functionPreEvaluationEventArg = new FunctionPreEvaluationEventArg ( varFuncName , funcArgs , this , null , genericsTypes , GetConcreteTypes ) ;
2093
2106
2094
2107
PreEvaluateFunction ? . Invoke ( this , functionPreEvaluationEventArg ) ;
2095
2108
@@ -2115,7 +2128,7 @@ where method.GetParameters()[0].ParameterType == objType // static extMethod(thi
2115
2128
}
2116
2129
else
2117
2130
{
2118
- FunctionEvaluationEventArg functionEvaluationEventArg = new FunctionEvaluationEventArg ( varFuncName , Evaluate , funcArgs , this , genericTypes : genericsTypes , evaluateGenericTypes : GetConcreteTypes ) ;
2131
+ FunctionEvaluationEventArg functionEvaluationEventArg = new FunctionEvaluationEventArg ( varFuncName , funcArgs , this , genericTypes : genericsTypes , evaluateGenericTypes : GetConcreteTypes ) ;
2119
2132
2120
2133
EvaluateFunction ? . Invoke ( this , functionEvaluationEventArg ) ;
2121
2134
@@ -2631,7 +2644,7 @@ protected virtual void CorrectStackWithUnaryPlusOrMinusBeforeParenthisIfNecessar
2631
2644
}
2632
2645
}
2633
2646
2634
- protected virtual bool EvaluateIndexing ( string expression , Stack < object > stack , ref int i )
2647
+ protected virtual bool EvaluateIndexingOperator ( string expression , Stack < object > stack , ref int i )
2635
2648
{
2636
2649
if ( ! OptionIndexingActive )
2637
2650
return false ;
@@ -2687,6 +2700,10 @@ protected virtual bool EvaluateIndexing(string expression, Stack<object> stack,
2687
2700
return true ;
2688
2701
}
2689
2702
2703
+ //IndexingPreEvaluationEventArg indexingPreEvaluationEventArg = new IndexingPreEvaluationEventArg(innerExp.ToString(), this, left);
2704
+
2705
+ //PreEvaluateIndexing?.Invoke(this, indexingPreEvaluationEventArg);
2706
+
2690
2707
dynamic right = Evaluate ( innerExp . ToString ( ) ) ;
2691
2708
ExpressionOperator op = indexingBeginningMatch . Length == 2 ? ExpressionOperator . IndexingWithNullConditional : ExpressionOperator . Indexing ;
2692
2709
@@ -4003,7 +4020,7 @@ public enum OptionOnNoReturnKeywordFoundInScriptAction
4003
4020
4004
4021
public partial class ExpressionOperator : IEquatable < ExpressionOperator >
4005
4022
{
4006
- protected static uint indexer = 0 ;
4023
+ protected static uint indexer ;
4007
4024
4008
4025
protected ExpressionOperator ( )
4009
4026
{
@@ -4191,6 +4208,9 @@ public ExpressionEvaluatorSecurityException(string message, Exception innerExcep
4191
4208
{ }
4192
4209
}
4193
4210
4211
+ /// <summary>
4212
+ /// Infos about the variable, attribut or property that is currently evaluate
4213
+ /// </summary>
4194
4214
public partial class VariableEvaluationEventArg : EventArgs
4195
4215
{
4196
4216
private readonly Func < string , Type [ ] > evaluateGenericTypes ;
@@ -4267,6 +4287,9 @@ public Type[] EvaluateGenericTypes()
4267
4287
}
4268
4288
}
4269
4289
4290
+ /// <summary>
4291
+ /// Infos about the variable, attribut or property that is currently evaluate
4292
+ /// </summary>
4270
4293
public partial class VariablePreEvaluationEventArg : VariableEvaluationEventArg
4271
4294
{
4272
4295
public VariablePreEvaluationEventArg ( string name , ExpressionEvaluator evaluator = null , object onInstance = null , string genericTypes = null , Func < string , Type [ ] > evaluateGenericTypes = null )
@@ -4279,17 +4302,18 @@ public VariablePreEvaluationEventArg(string name, ExpressionEvaluator evaluator
4279
4302
public bool CancelEvaluation { get ; set ; }
4280
4303
}
4281
4304
4305
+ /// <summary>
4306
+ /// Infos about the function or method that is currently evaluate
4307
+ /// </summary>
4282
4308
public partial class FunctionEvaluationEventArg : EventArgs
4283
4309
{
4284
- private readonly Func < string , object > evaluateFunc ;
4285
4310
private readonly Func < string , Type [ ] > evaluateGenericTypes ;
4286
4311
private readonly string genericTypes ;
4287
4312
4288
- public FunctionEvaluationEventArg ( string name , Func < string , object > evaluateFunc , List < string > args = null , ExpressionEvaluator evaluator = null , object onInstance = null , string genericTypes = null , Func < string , Type [ ] > evaluateGenericTypes = null )
4313
+ public FunctionEvaluationEventArg ( string name , List < string > args = null , ExpressionEvaluator evaluator = null , object onInstance = null , string genericTypes = null , Func < string , Type [ ] > evaluateGenericTypes = null )
4289
4314
{
4290
4315
Name = name ;
4291
4316
Args = args ?? new List < string > ( ) ;
4292
- this . evaluateFunc = evaluateFunc ;
4293
4317
This = onInstance ;
4294
4318
Evaluator = evaluator ;
4295
4319
this . genericTypes = genericTypes ;
@@ -4307,7 +4331,7 @@ public FunctionEvaluationEventArg(string name, Func<string, object> evaluateFunc
4307
4331
/// <returns></returns>
4308
4332
public object [ ] EvaluateArgs ( )
4309
4333
{
4310
- return Args . ConvertAll ( arg => evaluateFunc ( arg ) ) . ToArray ( ) ;
4334
+ return Args . ConvertAll ( arg => Evaluator . Evaluate ( arg ) ) . ToArray ( ) ;
4311
4335
}
4312
4336
4313
4337
/// <summary>
@@ -4317,7 +4341,7 @@ public object[] EvaluateArgs()
4317
4341
/// <returns>The evaluated arg</returns>
4318
4342
public object EvaluateArg ( int index )
4319
4343
{
4320
- return evaluateFunc ( Args [ index ] ) ;
4344
+ return Evaluator . Evaluate ( Args [ index ] ) ;
4321
4345
}
4322
4346
4323
4347
/// <summary>
@@ -4328,7 +4352,7 @@ public object EvaluateArg(int index)
4328
4352
/// <returns>The evaluated arg casted in the specified type</returns>
4329
4353
public T EvaluateArg < T > ( int index )
4330
4354
{
4331
- return ( T ) evaluateFunc ( Args [ index ] ) ;
4355
+ return Evaluator . Evaluate < T > ( Args [ index ] ) ;
4332
4356
}
4333
4357
4334
4358
/// <summary>
@@ -4389,10 +4413,94 @@ public Type[] EvaluateGenericTypes()
4389
4413
}
4390
4414
}
4391
4415
4416
+ /// <summary>
4417
+ /// Infos about the function or method that is currently evaluate
4418
+ /// </summary>
4392
4419
public partial class FunctionPreEvaluationEventArg : FunctionEvaluationEventArg
4393
4420
{
4394
- public FunctionPreEvaluationEventArg ( string name , Func < string , object > evaluateFunc , List < string > args = null , ExpressionEvaluator evaluator = null , object onInstance = null , string genericTypes = null , Func < string , Type [ ] > evaluateGenericTypes = null )
4395
- : base ( name , evaluateFunc , args , evaluator , onInstance , genericTypes , evaluateGenericTypes )
4421
+ public FunctionPreEvaluationEventArg ( string name , List < string > args = null , ExpressionEvaluator evaluator = null , object onInstance = null , string genericTypes = null , Func < string , Type [ ] > evaluateGenericTypes = null )
4422
+ : base ( name , args , evaluator , onInstance , genericTypes , evaluateGenericTypes )
4423
+ { }
4424
+
4425
+ /// <summary>
4426
+ /// If set to true cancel the evaluation of the current function or method and throw an exception that the function does not exists
4427
+ /// </summary>
4428
+ public bool CancelEvaluation { get ; set ; }
4429
+ }
4430
+
4431
+ /// <summary>
4432
+ /// Infos about the indexing that is currently evaluate
4433
+ /// </summary>
4434
+ public partial class IndexingEvaluationEventArg : EventArgs
4435
+ {
4436
+ public IndexingEvaluationEventArg ( string arg , ExpressionEvaluator evaluator , object onInstance )
4437
+ {
4438
+ Arg = arg ;
4439
+ This = onInstance ;
4440
+ Evaluator = evaluator ;
4441
+ }
4442
+
4443
+ /// <summary>
4444
+ /// The not evaluated args of the indexing
4445
+ /// </summary>
4446
+ public string Arg { get ; set ; }
4447
+
4448
+ /// <summary>
4449
+ /// The instance of the object on which the indexing is called.
4450
+ /// </summary>
4451
+ public object This { get ; }
4452
+
4453
+ private object returnValue ;
4454
+
4455
+ /// <summary>
4456
+ /// To set the result value of the indexing
4457
+ /// </summary>
4458
+ public object Value
4459
+ {
4460
+ get { return returnValue ; }
4461
+ set
4462
+ {
4463
+ returnValue = value ;
4464
+ HasValue = true ;
4465
+ }
4466
+ }
4467
+
4468
+ /// <summary>
4469
+ /// if <c>true</c> the indexing evaluation has been done, if <c>false</c> it means that the indexing does not exist.
4470
+ /// </summary>
4471
+ public bool HasValue { get ; set ; }
4472
+
4473
+ /// <summary>
4474
+ /// A reference on the current expression evaluator.
4475
+ /// </summary>
4476
+ public ExpressionEvaluator Evaluator { get ; }
4477
+
4478
+ /// <summary>
4479
+ /// Get the values of the indexing's args.
4480
+ /// </summary>
4481
+ /// <returns></returns>
4482
+ public object EvaluateArg ( )
4483
+ {
4484
+ return Evaluator . Evaluate ( Arg ) ;
4485
+ }
4486
+
4487
+ /// <summary>
4488
+ /// Get the values of the indexing's args.
4489
+ /// </summary>
4490
+ /// <returns></returns>
4491
+ public T EvaluateArg < T > ( )
4492
+ {
4493
+ return Evaluator . Evaluate < T > ( Arg ) ;
4494
+ }
4495
+ }
4496
+
4497
+ /// <summary>
4498
+ /// Infos about the indexing that is currently evaluate
4499
+ /// </summary>
4500
+ public partial class IndexingPreEvaluationEventArg : IndexingEvaluationEventArg
4501
+ {
4502
+ public IndexingPreEvaluationEventArg ( string arg , ExpressionEvaluator evaluator , object onInstance )
4503
+ : base ( arg , evaluator , onInstance )
4396
4504
{ }
4397
4505
4398
4506
/// <summary>
0 commit comments