Skip to content

Commit 7bde9be

Browse files
author
Sébastien Geiser
committed
Correct Script Event name and add Script Evaluated event
1 parent f034e50 commit 7bde9be

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

CodingSeb.ExpressionEvaluator/ExpressionEvaluator.cs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -929,12 +929,17 @@ public IDictionary<string, object> Variables
929929
}
930930

931931
/// <summary>
932-
/// Is fired just before an scriptExpression is evaluate.<para/>
933-
/// Allow to redefine the scriptExpression to evaluate or to force a result value.
932+
/// Is fired just before a script is evaluate.<para/>
933+
/// Allow to redefine the script to evaluate or to force a result value.
934934
/// </summary>
935-
public event EventHandler<ExpressionEvaluationEventArg> ScriptExpressionEvaluating;
936-
937-
935+
public event EventHandler<ExpressionEvaluationEventArg> ScriptEvaluating;
936+
937+
/// <summary>
938+
/// Is fired just before to return the script evaluation.<para/>
939+
/// Allow to modify on the fly the result of the evaluation.
940+
/// </summary>
941+
public event EventHandler<ExpressionEvaluationEventArg> ScriptEvaluated;
942+
938943
/// <summary>
939944
/// Is fired just before an expression is evaluate.<para/>
940945
/// Allow to redefine the expression to evaluate or to force a result value.
@@ -1095,7 +1100,7 @@ public virtual object ScriptEvaluate(string script)
10951100

10961101
ExpressionEvaluationEventArg expressionEvaluationEventArg = new ExpressionEvaluationEventArg(script, this);
10971102

1098-
ExpressionEvaluating?.Invoke(this, expressionEvaluationEventArg);
1103+
ScriptEvaluating?.Invoke(this, expressionEvaluationEventArg);
10991104

11001105
script = expressionEvaluationEventArg.Expression;
11011106

@@ -1108,11 +1113,26 @@ public virtual object ScriptEvaluate(string script)
11081113
object result = ScriptEvaluate(script, ref isReturn, ref isBreak, ref isContinue);
11091114

11101115
if (isBreak)
1116+
{
11111117
throw new ExpressionEvaluatorSyntaxErrorException("[break] keyword executed outside a loop");
1118+
}
11121119
else if (isContinue)
1120+
{
11131121
throw new ExpressionEvaluatorSyntaxErrorException("[continue] keyword executed outside a loop");
1122+
}
11141123
else
1124+
{
1125+
expressionEvaluationEventArg = new ExpressionEvaluationEventArg(script, this, result);
1126+
1127+
ScriptEvaluated?.Invoke(this, expressionEvaluationEventArg);
1128+
1129+
if (expressionEvaluationEventArg.HasValue)
1130+
{
1131+
result = expressionEvaluationEventArg.Value;
1132+
}
1133+
11151134
return result;
1135+
}
11161136
}
11171137
finally
11181138
{

0 commit comments

Comments
 (0)