nreco / lambdaparser

Runtime parser for string expressions (formulas, method calls). Builds dynamic LINQ expression tree and compiles it to lambda delegate.
http://www.nrecosite.com/
MIT License
309 stars 55 forks source link

Variables in expressions #42

Closed VitaliyMF closed 1 year ago

VitaliyMF commented 1 year ago

Motivation: in complex expressions where the same calculation result may be used more than once it expression may become monstrous because of copy-pastes of the same sub-expression, and also this causes multiple evaluations of the same value.

To prevent that let's add support of local variables that may be defined in that way:

var a = 5; var b = fromContext*2;  b>a ? b : a 

To keep full backward compatibility variables syntax should be controlled via LambdaParser.AllowVars property (false by default).

VitaliyMF commented 1 year ago

Shipped in 1.1.0