Skip to content

Commit 7bb4995

Browse files
committed
Add the current Evaluator in VariableEvaluationEventArg and FunctionEvaluationEventArg
1 parent a5db728 commit 7bb4995

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

CodingSeb.ExpressionEvaluator/ExpressionEvaluator.cs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,6 @@ public ExpressionEvaluator(Dictionary<string, object> variables) : this()
746746
#region Main evaluate methods (Expressions and scripts ==> public)
747747

748748
private bool inScript = false;
749-
750749

751750
/// <summary>
752751
/// Evaluate a script (multiple expressions separated by semicolon)
@@ -1570,7 +1569,7 @@ private bool EvaluateVarOrFunc(string expr, string restOfExpression, Stack<objec
15701569
}
15711570
else
15721571
{
1573-
FunctionEvaluationEventArg functionEvaluationEventArg = new FunctionEvaluationEventArg(varFuncName, Evaluate, funcArgs, obj);
1572+
FunctionEvaluationEventArg functionEvaluationEventArg = new FunctionEvaluationEventArg(varFuncName, Evaluate, funcArgs, this, obj);
15741573

15751574
EvaluateFunction?.Invoke(this, functionEvaluationEventArg);
15761575

@@ -1665,7 +1664,7 @@ private bool EvaluateVarOrFunc(string expr, string restOfExpression, Stack<objec
16651664
}
16661665
else
16671666
{
1668-
FunctionEvaluationEventArg functionEvaluationEventArg = new FunctionEvaluationEventArg(varFuncName, Evaluate, funcArgs);
1667+
FunctionEvaluationEventArg functionEvaluationEventArg = new FunctionEvaluationEventArg(varFuncName, Evaluate, funcArgs, this);
16691668

16701669
EvaluateFunction?.Invoke(this, functionEvaluationEventArg);
16711670

@@ -1762,7 +1761,7 @@ private bool EvaluateVarOrFunc(string expr, string restOfExpression, Stack<objec
17621761
}
17631762
else
17641763
{
1765-
VariableEvaluationEventArg variableEvaluationEventArg = new VariableEvaluationEventArg(varFuncName, obj);
1764+
VariableEvaluationEventArg variableEvaluationEventArg = new VariableEvaluationEventArg(varFuncName, this, obj);
17661765

17671766
EvaluateVariable?.Invoke(this, variableEvaluationEventArg);
17681767

@@ -1867,7 +1866,7 @@ private bool EvaluateVarOrFunc(string expr, string restOfExpression, Stack<objec
18671866
}
18681867
else
18691868
{
1870-
VariableEvaluationEventArg variableEvaluationEventArg = new VariableEvaluationEventArg(varFuncName);
1869+
VariableEvaluationEventArg variableEvaluationEventArg = new VariableEvaluationEventArg(varFuncName, this);
18711870

18721871
EvaluateVariable?.Invoke(this, variableEvaluationEventArg);
18731872

@@ -3024,10 +3023,11 @@ public class VariableEvaluationEventArg : EventArgs
30243023
/// Constructor of the VariableEvaluationEventArg
30253024
/// </summary>
30263025
/// <param name="name">The name of the variable to Evaluate</param>
3027-
public VariableEvaluationEventArg(string name, object onInstance = null)
3026+
public VariableEvaluationEventArg(string name, ExpressionEvaluator evaluator = null, object onInstance = null)
30283027
{
30293028
Name = name;
30303029
This = onInstance;
3030+
Evaluator = evaluator;
30313031
}
30323032

30333033
/// <summary>
@@ -3060,18 +3060,24 @@ public object Value
30603060
/// Otherwise is set to null.
30613061
/// </summary>
30623062
public object This { get; private set; } = null;
3063+
3064+
/// <summary>
3065+
/// A reference on the current expression evaluator.
3066+
/// </summary>
3067+
public ExpressionEvaluator Evaluator { get; private set; }
30633068
}
30643069

30653070
public class FunctionEvaluationEventArg : EventArgs
30663071
{
30673072
private readonly Func<string, object> evaluateFunc = null;
30683073

3069-
public FunctionEvaluationEventArg(string name, Func<string, object> evaluateFunc, List<string> args = null, object onInstance = null)
3074+
public FunctionEvaluationEventArg(string name, Func<string, object> evaluateFunc, List<string> args = null, ExpressionEvaluator evaluator = null, object onInstance = null)
30703075
{
30713076
Name = name;
30723077
Args = args ?? new List<string>();
30733078
this.evaluateFunc = evaluateFunc;
30743079
This = onInstance;
3080+
Evaluator = evaluator;
30753081
}
30763082

30773083
/// <summary>
@@ -3139,6 +3145,11 @@ public object Value
31393145
/// Otherwise is set to null.
31403146
/// </summary>
31413147
public object This { get; private set; } = null;
3148+
3149+
/// <summary>
3150+
/// A reference on the current expression evaluator.
3151+
/// </summary>
3152+
public ExpressionEvaluator Evaluator { get; private set; }
31423153
}
31433154

31443155
#endregion

0 commit comments

Comments
 (0)