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

TypeOperatorDescriptionSupport
Primaryx.yMember accessSupported
Primaryx?.yNull-conditional Member accessSupported
Primaryx?[y]Null-conditional indexSupported
Primaryf(x)InvocationSupported
Primarya[x]IndexSupported
Primaryx++Postfix incrementSupported Warning change the state of the postfixed element
Primaryx--Postfix decrementSupported Warning change the state of the postfixed element
PrimarynewInstanciateSupported you can also use new() function
PrimarytypeofGet the System.Type instance for a typeSupported
PrimarycheckedEnable overflow checkingNot Supported
PrimaryuncheckedDisable overflow checkingNot Supported
Primarydefault(T)Default value of a typeSupported
PrimarydelegateAnonymous methodNot Supported
PrimarysizeofNumber of bytes used by a variable or a typeSupported
Primary->DereferenceNot Supported
Unary+xPositive valueSupported
Unary-xNegative valueSupported
Unary!xLogical NegationSupported
Unary~xBitwise complementSupported
Unary++xPrefix incrementSupported Warning change the state of the prefixed element
Unary--xPrefix decrementSupported Warning change the state of the prefixed element
Unary(T)xExplicit castSupported
UnaryawaitAwait (for async methods)Not Supported
Unary&xAdress ofNot Supported
Unary*xPointer indirectionNot Supported
Multiplicativex * yMultiplicationSupported
Multiplicativex / yDivisionSupported
Multiplicativex % yModulus (Integer remainder)Supported
Additivex + yAdditionSupported
Additivex - ySubstractionSupported
Shiftx << yLeft shift (bits)Supported
Shiftx >> yRight shift (bits)Supported
Relationalx < yLess thanSupported
Relationalx > yGreater thanSupported
Relationalx <= yLess than or equalSupported
Relationalx >= yGreater than or equalSupported
Type-testingisType testingSupported
Type-testingasType conversionNot Supported
Equalityx == yEquality comparisonSupported
Equalityx != yNot equalSupported
Logical ANDx & yLogical and (bits)Supported
Logical XORx ^ yLogical XOR (bits)Supported
Logical ORx | yLogical OR (bits)Supported
Conditional ANDx && yConditional and (booleans)Supported
Conditional ORx || yConditional or (booleans)Supported
Null-coalescingx ?? yNull coalescing (if null take that)Supported
Conditionalt ? x : yTernary conditional operatorSupported
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 :

ElementsWhat is changingOptions
Custom variablesThe variable in the Variables dictionary is changed and if the variable doesn't exists, it automatically created with the = operatorCan be disabled with evaluator.OptionVariableAssignationActive = false;
Properties or fields on objectsIf the property/field is not readonly it is changedCan be disabled with evaluator.OptionPropertyOrFieldSetActive = false;
Indexed object like arrays, list or dictionariesThe value at the specified index is changedCan be disabled with evaluator.OptionIndexingAssignationActive = false;

Here is the list of available assignation operator

OperatorSupport
=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

TypeKeywordSupport
SelectionifSupported
Selectionelse ifSupported
SelectionelseSupported
Selectionswitch caseNot yet supported
Iterationdo ... whileSupported
IterationforSupported
Iterationforeach, inSupported
IterationwhileSupported
JumpbreakSupported in do, for and while blocks
JumpcontinueSupported in do, for and while blocks
JumpgotoNot supported (But if you looked after it -> Booo !!! Bad code)
JumpreturnSupported
Jump/ExceptionthrowSupported
Exception Handlingtry-catchSupported
Exception Handlingtry-finallySupported
Exception Handlingtry-catch-finallySupported

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.

Clone this wiki locally