C# Eval Expression - Eval.Execute
Execute a C# expression and return the result.
You can specify parameter value to use in the expression from various way:
- Anonymous Type
- Argument Position
- Class Member
Under the hood, the fist time an expression is executed, it’s getting compiled and the delegate is stored in the memory before being returned and executed. All future call from the same expression will retrieve the delegate from the memory to optimize the performance.
Even with this optimization, if you have to evaluate multiple times the same expression, by example in a for loop, we highly recommend you to use directly the delegate returning from the Compile method instead.
Execute and return a strongly typed result
You can return the result as a strongly typed type:
- Eval.Execute<TResult>(string code)
- Eval.Execute<TResult>(string code, object parameters)
- Eval.Execute<TResult>(string code, params object parameters)
Execute and return an object result
You can return the result as an object:
- Eval.Execute(string code)
- Eval.Execute(string code, object parameters)
- Eval.Execute(string code, params object parameters)