FastExpressionCompiler 3.2.1

FastExpressionCompiler is 10-40x times faster than Expression.Compile()

Install-Package FastExpressionCompiler -Version 3.2.1
dotnet add package FastExpressionCompiler --version 3.2.1
<PackageReference Include="FastExpressionCompiler" Version="3.2.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FastExpressionCompiler --version 3.2.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: FastExpressionCompiler, 3.2.1"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install FastExpressionCompiler as a Cake Addin
#addin nuget:?package=FastExpressionCompiler&version=3.2.1

// Install FastExpressionCompiler as a Cake Tool
#tool nuget:?package=FastExpressionCompiler&version=3.2.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Release Notes

## v3.2.1 Bug-fix release

- fixed: #307 Switch with fall through throws "System.InvalidProgramException: 'Common Language Runtime detected an invalid program.'"

## v3.2.0 Bug-fix and optimization release

- fixed: #305 CompileFast generates incorrect code with arrays and printing
- fixed: added missing Expression.MakeCatchBlock
- optimized: memory of Expression of T
- optimized: for the custom MethodCallExpression
- optimized: adding the ConstantInt and ConstantOf without boxing and null constant with the less space


## v3.1.0 Feature and bug-fix release

- added: #297 Add custom Constant to string output in the ToCSharpString and ToExpressionString
- added: #303 Add CompilerFlags.ThrowOnNotSupportedException and throw NotSupportedExpressionException when the flag is passed to CompileFast
- fixed: #301 Another case of the InvalidOperationException in the Mapster
- fixed: ListInit compilation for the Dictionary
- fixed: the lookup for the non-public property setter


## v3.0.5 Bug-fix release

- fixed: another case in #301 InvalidOperationException in the Mapster
- fixed: multiple problems with the TryCatch C# and Expression string output


## v3.0.4 Bug-fix release

- fixed: #302 Error compiling expression with array access


## v3.0.3 Bug-fix release

- fixed: #301 InvalidOperationException in the Mapster
- fixed: small bugs in the Lambda ToCSharpString output


## v3.0.2 Bug-fix release

- fixed:  #300 Bad label content in ILGenerator in the Mapster benchmark with FEC V3
- fixed: Small issues with the `ToCSharpString()`, specifically in the TryCatch, and the Goto, and the Label expressions


## v3.0.1 Bug-fix release

fixed: #298 LightExpression with the NewExpression of 4 arguments has ArgumentCount = 3


## v3.0.0 - Major feature release

This version contains a lot of fixes and improvements and as-little-as-possible breaking changes.

### **FastExpressionCompiler** and **FastExpressionCompiler.LightExpression**

- Performance and memory consumption are improved, especially for the expressions with the closure and for expressions with the nested lambdas.
- More expression types are supported.
- Many fixes in the IL Emit.
- Added `ToCSharpString()` extension method to output the compile-able C# code described by the expression (tries hard).
- Added `ToExpressionString()` extension method to output the valid expression construction syntax, so given an expression object you'll get e.g. `Lambda(New(...))`.
- Added optional `enum CompilerFlags { Default, NoInvocationLambdaInlining, EnableDelegateDebugInfo}` parameter for the compilation
- `EnableDelegateDebugInfo` adds the diagnostic info into the compiled delegate including its source Expression and C# code. Can be used as following:
```cs
   var f = e.CompileFast(true, CompilerFlags.EnableDelegateDebugInfo);
   var di = f.Target as IDelegateDebugInfo;
   Assert.IsNotNull(di.Expression);
   Assert.IsNotNull(di.ExpressionString);
   Assert.IsNotNull(di.CSharpString);
```

### **FastExpressionCompiler.LightExpression**

- Now includes the `ExpressionVisitor`.
- Improves the compatibility (the drop-in replacement) between the `FastExpressionCompiler.LightExpression.Expression` and the `System.Linq.Expression`.
- Decreasing the memory consumed by the created expressions partially via implementing the `IArgumentProvider` and `IParameterProvider` for some expressions.


### The full list of the closed issues

[Milestone v3.0.0](https://github.com/dadhi/FastExpressionCompiler/milestone/19)

NuGet packages (23)

Showing the top 5 NuGet packages that depend on FastExpressionCompiler:

Package Downloads
Miruken
Miruken handles your application
RulesEngine
Rules Engine is a package for abstracting business logic/rules/policies out of the system. This works in a very simple way by giving you an ability to put your rules in a store outside the core logic of the system thus ensuring that any change in rules doesn't affect the core system.
ExpressionToCodeLib
Generates valid, readable C# from an expression tree, and can annotate that code with runtime values. Useful for e.g. code generation and unit testing assertions.
Dos.ORM
Dos.ORM(原Hxj.Data)于2009年发布、2015年正式开源,支持Core,该组件已在大量成熟项目中应用。初期开发过程中参考了NBear与MySoft,吸取了他们的一些精华,加入新思想,后期参考EF的Lambda语法进行大量扩展。官方网站:https://www.ITdos.com/Dos/ORM/Index.html,交流QQ群:60831381。
TestBase
*TestBase* gives you a flying start with - fluent assertions that are easy to extend - sharp error messages - tools to help you test with “heavyweight” dependencies on - AspNetCore.Mvc, AspNet.Mvc or WebApi Contexts - HttpClient - Ado.Net - Streams & Logging - Mix & match with your favourite test runners & assertions. ``` UnitUnderTest.Action() .ShouldNotBeNull() .ShouldEqualByValueExceptFor(new {Id=1, Descr=expected}, ignoreList ) .Payload .ShouldMatchIgnoringCase("I expected this") .Should(someOtherPredicate); .Items .ShouldAll(predicate) .ShouldContain(item) .ShouldNotContain(predicate) .Where(predicate) .SingleOrAssertFail() .ShouldEqualByValue().ShouldEqualByValueExceptFor(...).ShouldEqualByValueOnMembers() work with all kinds of object and collections, and report what differed. string.ShouldMatch(pattern).ShouldNotMatch().ShouldBeEmpty().ShouldNotBeEmpty() .ShouldNotBeNullOrEmptyOrWhiteSpace().ShouldEqualIgnoringCase() .ShouldContain().ShouldStartWith().ShouldEndWith().ShouldBeContainedIn(), ... numeric.ShouldBeBetween().ShouldEqualWithTolerance()....GreaterThan....LessThan...GreaterOrEqualTo ... ienumerable.ShouldAll().ShouldContain().ShouldNotContain().ShouldBeEmpty().ShouldNotBeEmpty() ... stream.ShouldHaveSameStreamContentAs().ShouldContain() value.ShouldBe().ShouldNotBe().ShouldBeOfType().ShouldBeAssignableTo()... ``` TestBase.HttpClient.Fake ``` new FakeHttpClient() .Setup(x=>x.RequestUri.PathAndQuery.StartsWith("/this")) .Returns(response) .Setup(x=>x.Method==HttpMethod.Put) .Returns(new HttpResponseMessage(HttpStatusCode.Accepted)); ``` TestBase.AdoNet ------------------ `FakeDbConnection` ``` - db.SetupForQuery(…) - db.SetupForExecuteNonQuery(…) - db.ShouldHaveUpdated("tableName", …) - db.ShouldHaveSelected("tableName", …) - db.ShouldHaveDeleted("tableName", …) - db.Verify( x=>x.CommandText.Matches("Insert [case] .*") && x.Parameters["id"].Value==1 ) - db .ShouldHaveInvoked(cmd => predicate(cmd)) .ShouldHaveParameter("name", value) ``` `RecordingDbConnection` TestBase.Mvc.AspNetCore & TestBase.Mvc for Mvc 4 & Mvc 5 -------------------------------------------------------- ``` ControllerUnderTest.WithControllerContext() .Action() .ShouldbeViewResult() .ShouldHaveModel<TModel>() .ShouldEqualByValue(expected) ControllerUnderTest.Action() .ShouldBeRedirectToRouteResult() .ShouldHaveRouteValue("expectedKey", [Optional] "expectedValue"); ShouldHaveViewDataContaining(), ShouldBeJsonResult() etc. ``` - Test AspNetCore controllers with zero setup using `controllerUnderTest.WithControllerContext(actionUnderTest)` - Test more complex AspNetCore controller/application dependencies using `HostedMvcTestFixtureBase` and specify your MVCApplications `Startup` class. ``` [TestCase("/dummy")] public async Task Put_Should_ReturnA(string url) { var httpClient=GivenClientForRunningServer<Startup>(); GivenRequestHeaders(httpClient, "CustomHeader", "HeaderValue1"); var result = await httpClient.PutAsync(url, json); result.ShouldBe_202Accepted(); } ``` For Mvc4 and Mvc 5, fake your http request &amp; context, and use the `RegisterRoutes` method of your actual application to set up `Controller.Url` ``` ControllerUnderTest .WithHttpContextAndRoutes( RouteConfig.RegisterRoutes, "/incomingurl" ); ApiControllerUnderTest.WithWebApiHttpContext<T>( httpMethod, requestUri, routeTemplate) ``` Testable Logging ``` // Extensions.Logging.ListOfString var log = new List<String>(); ILogger mslogger= new LoggerFactory().AddStringListLogger(log).CreateLogger("Test2"); // Serilog.Sinks.ListOfString Serilog.Logger slogger= new LoggerConfiguration().WriteTo.StringList(log).CreateLogger(); ```

GitHub repositories (7)

Showing the top 5 popular GitHub repositories that depend on FastExpressionCompiler:

Repository Stars
linq2db/linq2db
Linq to database provider.
MapsterMapper/Mapster
A fast, fun and stimulating object to object Mapper
microsoft/RulesEngine
A Json based Rules Engine with extensive Dynamic expression support
itdos/Dos.ORM
Dos.ORM于2009年发布、2015年正式开源,该组件已在数百个成熟项目中应用。初期开发过程中吸取了NBear与MySoft的一些精华并加入新思想,之后参考EF Lambda语法进行大量扩展。经过数十个版本的更新迭代发布全新v2.0版本,支持动态列/表、分库/分表等。官方网站:https://www.itdos.com/dos/orm/Index.html 交流群:60831381
EamonNerbonne/ExpressionToCode
Generates valid, readable C# from an Expression Tree.

Version History

Version Downloads Last updated
3.2.1 7,222 7/21/2021
3.2.0 27,032 6/14/2021
3.1.0 25,897 5/3/2021
3.1.0-preview-03 76 5/3/2021
3.1.0-preview-02 96 5/3/2021
3.1.0-preview-01 89 5/2/2021
3.0.6-preview-01 104 4/23/2021
3.0.5 1,082 4/21/2021
3.0.4 2,687 4/6/2021
3.0.3 683 4/1/2021
3.0.2 1,746 3/30/2021
3.0.1 176 3/27/2021
3.0.0 1,000 3/17/2021
3.0.0-preview-07 5,098 12/25/2020
3.0.0-preview-06 343 12/1/2020
3.0.0-preview-05 884 11/27/2020
3.0.0-preview-04 269 11/3/2020
3.0.0-preview-03 150 11/2/2020
3.0.0-preview-02 803 10/23/2020
3.0.0-preview-01 156 10/23/2020
2.0.0 267,054 1/25/2019
2.0.0-preview-03 1,124 11/9/2018
2.0.0-preview-02 799 10/25/2018
2.0.0-preview-01 549 10/24/2018
1.10.1 28,063 8/8/2018
1.10.0 644 8/3/2018
1.9.0 1,170 7/24/2018
1.8.0 20,766 6/24/2018
1.7.2 4,276 6/7/2018
1.7.1 17,673 3/27/2018
1.7.0 6,566 3/17/2018
1.6.0 18,229 12/3/2017
1.5.0 2,589 11/12/2017
1.4.0 7,537 9/9/2017
1.3.0 949 8/28/2017
1.2.2 1,224 8/8/2017
1.2.1 831 8/8/2017
1.2.0 818 8/8/2017
1.1.1 107,945 7/18/2017
1.1.0 753 7/13/2017
1.0.1 1,439 5/26/2017
1.0.0 1,491 4/2/2017
1.0.0-preview-04 756 3/31/2017
1.0.0-preview-03 1,135 3/30/2017
1.0.0-preview-02 737 3/29/2017
1.0.0-preview-01 839 3/23/2017