All Projects → nreco → Lambdaparser

nreco / Lambdaparser

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

Projects that are alternatives of or similar to Lambdaparser

ChatService
ChatService (SignalR).
Stars: ✭ 26 (-86.1%)
Mutual labels:  dotnetcore, dot-net
GatewayService
GatewayService (Ocelot).
Stars: ✭ 19 (-89.84%)
Mutual labels:  dotnetcore, dot-net
Designpatterns
Simple repository containing one simple example for all existing patterns in C#
Stars: ✭ 231 (+23.53%)
Mutual labels:  dotnetcore, dot-net
Architecture
.NET 6, ASP.NET Core 6, Entity Framework Core 6, C# 10, Angular 13, Clean Code, SOLID, DDD.
Stars: ✭ 2,285 (+1121.93%)
Mutual labels:  dotnetcore, dot-net
Dotnetcore
.NET 5 Nuget Packages.
Stars: ✭ 146 (-21.93%)
Mutual labels:  dotnetcore, dot-net
recommender
NReco Recommender is a .NET port of Apache Mahout CF java engine (standalone, non-Hadoop version)
Stars: ✭ 35 (-81.28%)
Mutual labels:  dotnetcore, dot-net
FineCodeCoverage
Visualize unit test code coverage easily for free in Visual Studio Community Edition (and other editions too)
Stars: ✭ 391 (+109.09%)
Mutual labels:  dotnetcore, dot-net
Nsubstitute
A friendly substitute for .NET mocking libraries.
Stars: ✭ 1,646 (+780.21%)
Mutual labels:  dotnetcore, dot-net
Netbarcode
Barcode generation library written in C# and .NET Standard 2
Stars: ✭ 149 (-20.32%)
Mutual labels:  dotnetcore, dot-net
Data
Fast DB-independent DAL for .NET Core: abstract queries, SQL commands builder, schema-less data access, POCO mapping (micro-ORM).
Stars: ✭ 150 (-19.79%)
Mutual labels:  dotnetcore, dot-net
Netcore Boilerplate
Boilerplate of API in .NET Core 3.1
Stars: ✭ 166 (-11.23%)
Mutual labels:  dotnetcore
Autocomplete
Persistent, simple, powerful and portable autocomplete library
Stars: ✭ 166 (-11.23%)
Mutual labels:  dotnetcore
Rocksdb Sharp
.net bindings for the rocksdb by facebook
Stars: ✭ 173 (-7.49%)
Mutual labels:  dotnetcore
Rafty
Implementation of RAFT consensus in .NET core
Stars: ✭ 182 (-2.67%)
Mutual labels:  dotnetcore
Surgingdemo
surging 使用入门示例。完成一个基本业务的增删改查示例,并运用Surging强大的分布式缓存功能
Stars: ✭ 165 (-11.76%)
Mutual labels:  dotnetcore
Aspnet Core 3 Registration Login Api
ASP.NET Core 3.1 API for User Management, Authentication and Registration
Stars: ✭ 173 (-7.49%)
Mutual labels:  dotnetcore
Storedprocedureefcore
Entity Framework Core extension to execute stored procedures
Stars: ✭ 164 (-12.3%)
Mutual labels:  dotnetcore
Litenetlib
Lite reliable UDP library for Mono and .NET
Stars: ✭ 2,179 (+1065.24%)
Mutual labels:  dot-net
Codehub
A UWP GitHub Client
Stars: ✭ 162 (-13.37%)
Mutual labels:  dot-net
Dalsoft.restclient
The C# REST Client - the only REST/ HTTP Client you will ever need
Stars: ✭ 185 (-1.07%)
Mutual labels:  dotnetcore

NReco LambdaParser

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 Release | AppVeyor

  • PCL (Portable) library: can be used with any .NET target: net40+sl5, net45+wp8+win8+wpa81, .NET Standards 1.3 (.NET Core apps)
  • any number of variables (values can be provided as dictionary or by callback delegate)
  • supports arithmetic operations (+, -, *, /, %), comparisons (==, !=, >, <, >=, <=), conditionals including (ternary) operator ( ? : )
  • access object properties, call methods and indexers, invoke delegates
  • dynamic typed variables: performs automatic type conversions to match method signature or arithmetic operations
  • create arrays and dictionaries with simplified syntax: new dictionary{ {"a", 1}, {"b", 2} } , new []{ 1, 2, 3}

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)

Custom values comparison

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

  • ValueComparer.NullComparison determines how comparison with null is handled. 2 options:
    • MinValue: null is treated as minimal possible value for any type - like .NET IComparer
    • Sql: null is not comparable with any type, including another null - like in SQL
  • 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).
var valComparer = new ValueComparer() { NullComparison = ValueComparer.NullComparisonMode.Sql };
var lambdaParser = new LambdaParser(valComparer); 

Who is using this?

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

License

Copyright 2016-2020 Vitaliy Fedorchenko

Distributed under the MIT license

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].