-
Notifications
You must be signed in to change notification settings - Fork 98
Operators and Keywords
ExpressionEvaluator manage a large set of C# operators (See C# Operators)
ExpressionEvaluator respect the C# precedence rules of operators
Here is a list of which operators are supported in ExpressionEvaluator or not
Type | Operator | Description | Support |
---|---|---|---|
Primary | x.y | Member access | Supported |
Primary | x?.y | Null-conditional Member access | Supported |
Primary | x?[y] | Null-conditional index | Supported |
Primary | f(x) | Invocation | Supported |
Primary | a[x] | Index | Supported |
Primary | x++ | Postfix increment | Supported Warning change the state of the postfixed element |
Primary | x-- | Postfix decrement | Supported Warning change the state of the postfixed element |
Primary | new | Instanciate | Supported you can also use new() function |
Primary | typeof | Get the System.Type instance for a type | Supported |
Primary | checked | Enable overflow checking | Not Supported |
Primary | unchecked | Disable overflow checking | Not Supported |
Primary | default(T) | Default value of a type | Supported |
Primary | delegate | Anonymous method | Not Supported |
Primary | sizeof | Number of bytes used by a variable or a type | Supported |
Primary | -> | Dereference | Not Supported |
Unary | +x | Positive value | Supported |
Unary | -x | Negative value | Supported |
Unary | !x | Logical Negation | Supported |
Unary | ~x | Bitwise complement | Supported |
Unary | ++x | Prefix increment | Supported Warning change the state of the prefixed element |
Unary | --x | Prefix decrement | Supported Warning change the state of the prefixed element |
Unary | (T)x | Explicit cast | Supported |
Unary | await | Await (for async methods) | Not Supported |
Unary | &x | Adress of | Not Supported |
Unary | *x | Pointer indirection | Not Supported |
Multiplicative | x * y | Multiplication | Supported |
Multiplicative | x / y | Division | Supported |
Multiplicative | x % y | Modulus (Integer remainder) | Supported |
Additive | x + y | Addition | Supported |
Additive | x - y | Substraction | Supported |
Shift | x << y | Left shift (bits) | Supported |
Shift | x >> y | Right shift (bits) | Supported |
Relational | x < y | Less than | Supported |
Relational | x > y | Greater than | Supported |
Relational | x <= y | Less than or equal | Supported |
Relational | x >= y | Greater than or equal | Supported |
Type-testing | is | Type testing | Supported |
Type-testing | as | Type conversion | Not Supported |
Equality | x == y | Equality comparison | Supported |
Equality | x != y | Not equal | Supported |
Logical AND | x & y | Logical and (bits) | Supported |
Logical XOR | x ^ y | Logical XOR (bits) | Supported |
Logical OR | x | y | Logical OR (bits) | Supported |
Conditional AND | x && y | Conditional and (booleans) | Supported |
Conditional OR | x || y | Conditional or (booleans) | Supported |
Null-coalescing | x ?? y | Null coalescing (if null take that) | Supported |
Conditional | t ? x : y | Ternary conditional operator | Supported |
Lambda | => | Lambda (Expressions and bodied) | Supported |
If you are not totally happy with these operators. There are also advanced ways to add, remove or redefine operators
Warning all of the following operators change the value of their left element.
Assignation operators (and also postfix operators (++ and --)) are usable on :
Elements | What is changing | Options |
---|---|---|
Custom variables | The variable in the Variables dictionary is changed and if the variable doesn't exists, it automatically created with the = operator | Can be disabled with evaluator.OptionVariableAssignationActive = false;
|
Properties or fields on objects | If the property/field is not readonly it is changed | Can be disabled with evaluator.OptionPropertyOrFieldSetActive = false;
|
Indexed object like arrays, list or dictionaries | The value at the specified index is changed | Can be disabled with evaluator.OptionIndexingAssignationActive = false;
|
Here is the list of available assignation operator
Operator | Support |
---|---|
= | Supported (Can be use to declare a new variable that will be injected in the Variables dictionary) |
+= | Supported |
-= | Supported |
*= | Supported |
/= | Supported |
%= | Supported |
&= | Supported |
|= | Supported |
^= | Supported |
<<= | Supported |
>>= | Supported |
??= | Supported (From version 1.4.17.0) |
An assignation of a variable that do not exists create it from the script. See Declare and init variables in scripts
In addition to simple expression evaluation you can also evaluate small scripts with the method :
//object ScriptEvaluate(string script)
evaluator.ScriptEvaluate(script);
Scripts are just a serie of expressions to evaluate separated with a ; character and leaded by severals additionals keywords.
Currently the following scripts keywords are supported
Type | Keyword | Support |
---|---|---|
Selection | if | Supported |
Selection | else if | Supported |
Selection | else | Supported |
Selection | switch case | Not yet supported |
Iteration | do ... while | Supported |
Iteration | for | Supported |
Iteration | foreach, in | Supported |
Iteration | while | Supported |
Jump | break | Supported in do, for and while blocks |
Jump | continue | Supported in do, for and while blocks |
Jump | goto | Not supported (But if you looked after it -> Booo !!! Bad code) |
Jump | return | Supported |
Jump/Exception | throw | Supported |
Exception Handling | try-catch | Supported |
Exception Handling | try-finally | Supported |
Exception Handling | try-catch-finally | Supported |
Remark : The way ScriptEvaluate works is to evaluate expressions one by one. There is no syntax check before the evaluation. So be aware that syntax or naming bugs only appears in execution and some code can already be evaluated at this time. Futhermore a syntaxic/naming bug in an if-else block for example can simply be ignored until the corresponding condition is met to evaluate the specific line of code.
- Getting Started
- Variables and Functions
- Operators and Keywords
- C# Types Management
- ExpandoObject
- Code Comments Management
- Advanced Customization and Hacking
- Caching
-
Options
- CultureInfoForNumberParsing
- OptionCaseSensitiveEvaluationActive
- OptionVariablesPersistenceCustomComparer
- OptionFluidPrefixingActive
- OptionForceIntegerNumbersEvaluationsAsDoubleByDefault
- OptionNumberParsingDecimalSeparator
- OptionNumberParsingThousandSeparator
- OptionFunctionArgumentsSeparator
- OptionInitializersSeparator
- OptionInlineNamespacesEvaluationRule
- OptionNewFunctionEvaluationActive
- OptionNewKeywordEvaluationActive
- OptionStaticMethodsCallActive
- OptionStaticProperiesGetActive
- OptionInstanceMethodsCallActive
- OptionInstanceProperiesGetActive
- OptionIndexingActive
- OptionStringEvaluationActive
- OptionCharEvaluationActive
- OptionEvaluateFunctionActive
- OptionVariableAssignationActive
- OptionPropertyOrFieldSetActive
- OptionIndexingAssignationActive
- OptionScriptEvaluateFunctionActive
- OptionOnNoReturnKeywordFoundInScriptAction
- OptionScriptNeedSemicolonAtTheEndOfLastExpression
- OptionAllowNonPublicMembersAccess
- Todo List