Skip to content

Commit 3ea6514

Browse files
authored
Add doc on onthe fly instance properties and methods definition
1 parent 16b7ea7 commit 3ea6514

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ It is largely based on and inspired by the following resources [this post on st
88
* System.Math methods and constants directly available (some like Max, Min, Avg are improved)
99
* Some useful [functions](#standard-functions) for example to create List and Arrays
1010
* [Custom variables definition](#custom-variables)
11-
* [On the fly variables and functions evaluation](#on-the-fly-variables-and-functions-evaluation) (To easily extend possibilities)
11+
* [On the fly variables and functions evaluation](#on-the-fly-variables-and-functions-evaluation) (To easily extend possibilities, Manage also on instance Property and Methods)
1212
* [A large set of C# operators availables](#operators)
1313
* Instance and static methods and properties access like as in C#
1414
* You can call Methods and/or Properties on your own classes (just pass a object as custom variables)
@@ -200,6 +200,7 @@ The evaluation of functions names is case insensitive.
200200
## On the fly variables and functions evaluation
201201
In addition to custom variables, you can add variables and/or functions with on the fly evaluation.
202202
2 C# events are provided that are fired when variables or functions are not fund as standard ones in evaluation time.
203+
Can be use to define or redefine on object instance methods or properties.
203204

204205
```C#
205206
ExpressionEvaluator evaluator = new ExpressionEvaluator();
@@ -213,6 +214,10 @@ private void ExpressionEvaluator_EvaluateVariable(object sender, VariableEvaluat
213214
{
214215
e.Value = 8;
215216
}
217+
else if(e.Name.Equals("MultipliedBy2") && e.This is int intValue)
218+
{
219+
e.Value = intValue * 2;
220+
}
216221
}
217222

218223
private void ExpressionEvaluator_EvaluateFunction(object sender, FunctionEvaluationEventArg e)
@@ -221,6 +226,10 @@ private void ExpressionEvaluator_EvaluateFunction(object sender, FunctionEvaluat
221226
{
222227
e.Value = $"Hello {e.EvaluateArg(0)}";
223228
}
229+
else if(e.Name.Equals("Add") && e.This is int intValue)
230+
{
231+
e.Value = intValue + (int)e.EvaluateArg(0);
232+
}
224233
}
225234
```
226235
```
@@ -229,6 +238,12 @@ myVar + 2
229238

230239
SayHello("Bob")
231240
Hello Bob
241+
242+
3.MultipliedBy2
243+
6
244+
245+
3.Add(2)
246+
5
232247
```
233248

234249
## Go fluid with a simple methods prefixing convention

0 commit comments

Comments
 (0)