ExpressionEval documentation

1. Description

ExpressionEval is an Expression Evaluator back-end component. It allows you to evaluate arbitrary string expressions sush as: logical (Or, And, Not, Xor), comparison (=, <>, <=, <, >, >=) or calculation (+, -, *, /) in an application. Variables and functions can also be used in expressions. The component is configurable: double decimal separator, string tag,… This component is a library provided in .NET Standard 2.0 and in .NET Framework 4.5.

2. Key features

  • Input expression as a raw string,
  • The expression can be simple or complex,
  • Can have nested expression, one or more,
  • Comparison operator possible: Or, And, Xor, Not,
  • Comparison operator can be defined in english (Or, And, Xor, Not) or in french (Ou, Et, Oux, Non),
  • Logical operator possible: =, <>, >, <, >=, <=,
  • Calculation operator managed: +, -, * /,
  • Value type managed: string, int, double, bool,
  • Predefined boolean value can be used: true/False (in english) vrai/faux (in french),
  • You can use variable, one or more,
  • You can use function call, with parameters or not,
  • Wrong expression error management.

3. Get the component

The last available version is: 0.8.

The library is provided in two targets: .NET Standard 2.0 and .NET 4.5

You can get the packet from nuget here: nuget.org/packages/Pierlam.ExpressionEval

4. Get code samples

You can find several code samples in a Visual Studio solution here: 

https://github.com/Pierlam/ExpressionEvalSamples

5. Examples of expressions

With this component , you can evaluate a lot of different expressions, for examples:

a=b
a>=b
(a and b)or(c or d)
not(a)
(a+b)*c
a+b*c+d
...

More examples of expressions you can evaluate with the component are described: here.

6. Evaluate an expression, the process

The basic way to use the ExpressionEval component is to input an expression, parse it, define variables, evaluate the expression and then get the result. All this process is explained: here.

7. Manage variables

You can use variables in expression. One or several, as needed. For example this expression define two variables, ‘a’ and ‘b’:

(a=b)

How to use and define variables is defined : here.

8. Data type

The data, constant values or variables can be one of these types: bool ,int, string or double.

9. Use function call

It’s possible to use function call in expression. Function call have to be attached to function code. Example of an expression containing the function call: fct with one parameter, the variable ‘a’. This function call has to be attached to a function code which will be executed.

fct(a)

How to use function call in expression is explained: here.

10. Configure the evaluator

It’s possible to modify the default behavior of the evalutor component by configuring it. You can change the language used for keywords, change the decimal separator and function parameters separator, change the string start and end tags. How to configure the evaluator is explained in details: here.

11. Error management

The component provide a complete and fine-grained management of errors when an expression is parsed and executed/evaluated. Several error code , more than 50, are available to describe with precision the error.

Refer to this page to have more details: here.