A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/nreco/lambdaparser below:

nreco/lambdaparser: Runtime parser for string expressions (formulas, method calls). Builds dynamic LINQ expression tree and compiles it to lambda delegate.

Runtime parser for string expressions (formulas, method calls, properties/fields/arrays accessors). LambdaParser builds dynamic LINQ expression tree and compiles it to the lambda delegate. Types are resolved at run-time like in dynamic languages.

Nuget package: NReco.LambdaParser

var lambdaParser = new NReco.Linq.LambdaParser();

var varContext = new Dictionary<string,object>();
varContext["pi"] = 3.14M;
varContext["one"] = 1M;
varContext["two"] = 2M;
varContext["test"] = "test";
Console.WriteLine( lambdaParser.Eval("pi>one && 0<one ? (1+8)/3+1*two : 0", varContext) ); // --> 5
Console.WriteLine( lambdaParser.Eval("test.ToUpper()", varContext) ); // --> TEST

(see unit tests for more expression examples)

By default LambdaParser uses ValueComparer for values comparison. You can provide your own implementation or configure its option to get desired behaviour:

var valComparer = new ValueComparer() { NullComparison = ValueComparer.NullComparisonMode.Sql };
var lambdaParser = new LambdaParser(valComparer); 

The UseCache property determines whether the LambdaParser should cache parsed expressions. By default, UseCache is set to true, meaning expressions are cached to improve performance for repeated evaluations of the same expression.

Therefore, using a singleton instance of LambdaParser is recommended, rather than creating a new instance each time.

You can disable caching by setting UseCache to false if you want to save memory, especially when evaluating a large number of unique expressions.

var lambdaParser = new LambdaParser();
lambdaParser.UseCache = false;

NReco.LambdaParser is in production use at SeekTable.com and PivotData microservice (used for user-defined calculated cube members: formulas, custom formatting).

Copyright 2016-2024 Vitaliy Fedorchenko and contributors

Distributed under the MIT license


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4