{"id":13431144,"url":"https://github.com/nreco/lambdaparser","last_synced_at":"2025-04-07T23:12:57.312Z","repository":{"id":45410638,"uuid":"50671141","full_name":"nreco/lambdaparser","owner":"nreco","description":"Runtime parser for string expressions (formulas, method calls). Builds dynamic LINQ expression tree and compiles it to lambda delegate.","archived":false,"fork":false,"pushed_at":"2024-07-12T11:26:38.000Z","size":102,"stargazers_count":313,"open_issues_count":14,"forks_count":56,"subscribers_count":26,"default_branch":"master","last_synced_at":"2025-03-31T22:24:18.559Z","etag":null,"topics":["dot-net","dotnetcore","evalexpr","evaluator","lambda-expressions","lambda-interpreter","math-expressions"],"latest_commit_sha":null,"homepage":"http://www.nrecosite.com/","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nreco.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-01-29T15:29:30.000Z","updated_at":"2025-03-17T14:12:58.000Z","dependencies_parsed_at":"2024-01-28T20:06:21.365Z","dependency_job_id":"d91f3431-d0c3-4424-ac68-7154b01ac6df","html_url":"https://github.com/nreco/lambdaparser","commit_stats":{"total_commits":52,"total_committers":6,"mean_commits":8.666666666666666,"dds":0.09615384615384615,"last_synced_commit":"412f304575127bd992f3a8ab19d4f66b3b0f9c4a"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nreco%2Flambdaparser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nreco%2Flambdaparser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nreco%2Flambdaparser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nreco%2Flambdaparser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nreco","download_url":"https://codeload.github.com/nreco/lambdaparser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247744335,"owners_count":20988783,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dot-net","dotnetcore","evalexpr","evaluator","lambda-expressions","lambda-interpreter","math-expressions"],"created_at":"2024-07-31T02:01:00.847Z","updated_at":"2025-04-07T23:12:57.290Z","avatar_url":"https://github.com/nreco.png","language":"C#","funding_links":[],"categories":["Frameworks, Libraries and Tools","C\\#","框架, 库和工具","Misc","C# #"],"sub_categories":["Misc","大杂烩"],"readme":"# NReco LambdaParser\nRuntime 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. \n\nNuGet | Windows x64 | Linux\n--- | --- | ---\n[![NuGet Release](https://img.shields.io/nuget/v/NReco.LambdaParser.svg)](https://www.nuget.org/packages/NReco.LambdaParser/) | [![AppVeyor](https://img.shields.io/appveyor/ci/nreco/lambdaparser/master.svg)](https://ci.appveyor.com/project/nreco/lambdaparser) | ![Tests](https://github.com/nreco/lambdaparser/actions/workflows/dotnet-test.yml/badge.svg) \n\n* can be used in *any* .NET app: net45 (legacy .NET Framework apps), netstandard1.3 (.NET Core apps), netstandard2.0 (all modern .NET apps).\n* any number of expression arguments (values can be provided as dictionary or by callback delegate)\n* supports arithmetic operations (+, -, *, /, %), comparisons (==, !=, \u003e, \u003c, \u003e=, \u003c=), conditionals including (ternary) operator ( boolVal ? whenTrue : whenFalse )\n* access object properties, call methods and indexers, invoke delegates\n* dynamic typed variables: performs automatic type conversions to match method signature or arithmetic operations\n* create arrays and dictionaries with simplified syntax: `new dictionary{ {\"a\", 1}, {\"b\", 2} }` , `new []{ 1, 2, 3}`\n* local variables that may go before main expression: `var a = 5; var b = contextVar/total*100;`  (disabled by default, to enable use `LambdaParser.AllowVars` property)\n\nNuget package: [NReco.LambdaParser](https://www.nuget.org/packages/NReco.LambdaParser/)\n\n```\nvar lambdaParser = new NReco.Linq.LambdaParser();\n\nvar varContext = new Dictionary\u003cstring,object\u003e();\nvarContext[\"pi\"] = 3.14M;\nvarContext[\"one\"] = 1M;\nvarContext[\"two\"] = 2M;\nvarContext[\"test\"] = \"test\";\nConsole.WriteLine( lambdaParser.Eval(\"pi\u003eone \u0026\u0026 0\u003cone ? (1+8)/3+1*two : 0\", varContext) ); // --\u003e 5\nConsole.WriteLine( lambdaParser.Eval(\"test.ToUpper()\", varContext) ); // --\u003e TEST\n```\n(see [unit tests](https://github.com/nreco/lambdaparser/blob/master/src/NReco.LambdaParser.Tests/LambdaParserTests.cs) for more expression examples)\n\n## Custom values comparison\nBy default `LambdaParser` uses `ValueComparer` for values comparison. You can provide your own implementation or configure its option to get desired behaviour:\n* `ValueComparer.NullComparison` determines how comparison with `null` is handled. 2 options: \n  * `MinValue`: null is treated as minimal possible value for any type - like .NET IComparer\n  * `Sql`: null is not comparable with any type, including another null - like in SQL\n* `ValueComparer.SuppressErrors` allows to avoid convert exception. If error appears during comparison exception is not thrown and this means that values are not comparable (= any condition leads to `false`).\n```\nvar valComparer = new ValueComparer() { NullComparison = ValueComparer.NullComparisonMode.Sql };\nvar lambdaParser = new LambdaParser(valComparer); \n```\n### Caching Expressions\n\nThe `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. \n\nTherefore, using a singleton instance of `LambdaParser` is recommended, rather than creating a new instance each time.\n\nYou can disable caching by setting UseCache to false if you want to save memory, especially when evaluating a large number of unique expressions.\n\n```csharp\nvar lambdaParser = new LambdaParser();\nlambdaParser.UseCache = false;\n```\n\n## Who is using this?\nNReco.LambdaParser is in production use at [SeekTable.com](https://www.seektable.com/) and [PivotData microservice](https://www.nrecosite.com/pivotdata_service.aspx) (used for user-defined calculated cube members: formulas, custom formatting).\n\n## License\nCopyright 2016-2024 Vitaliy Fedorchenko and contributors\n\nDistributed under the MIT license\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnreco%2Flambdaparser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnreco%2Flambdaparser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnreco%2Flambdaparser/lists"}