Fast Compiler for C# Expression Trees and the lightweight LightExpression alternative. Diagnostic and code generation tools for the expressions.
This version contains a lot of fixes and improvements and as-little-as-possible breaking changes.
ToCSharpString()
extension method to output the compile-able C# code described by the expression (tries hard).ToExpressionString()
extension method to output the valid expression construction syntax, so given an expression object you'll get e.g. Lambda(New(...))
.enum CompilerFlags { Default, NoInvocationLambdaInlining, EnableDelegateDebugInfo}
parameter for the compilationEnableDelegateDebugInfo
adds the diagnostic info into the compiled delegate including its source Expression and C# code. Can be used as following: 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);
ExpressionVisitor
.FastExpressionCompiler.LightExpression.Expression
and the System.Linq.Expression
.IArgumentProvider
and IParameterProvider
for some expressions.Contains breaking changes, but likely or lucky you'll need to re-compile only.
V2 was developed with a strong help of @jogibear9988, @dzmitry-lahoda, @MaceWindu, and other contributors - kudos to all of them!
FEC package now is split in two: [FastExpressionCompiler (FEC)] and [FastExpressionCompiler.LightExpression (FEC.LE)]. The packages are not dependent on each other and may be used together.
FEC.LightExpression allows a drop-in replacement for manually created expression, the only change is different namespace using. LE.Expression is "lighter" because it is faster created and consumes less memory. It does it by avoiding most of compatibility and verification checks. But it does not mean it is not safe! You can convert it to System Expression as easy as calling ToExpression
or ToLambdaExpression
and it will run the usual verification. This conversation also enables fallback to Expression.Compile
inside the CompileFast
.
ExpressionInfo
and supporting logic is moved from FEC to FEC.LEExpressionInfo
is renamed to Expression
but moved into new namespace FastExpressionCompiler.LightExpression
ExpressionInfo
noise and now is much simpler and lost 33% LOC.LIGHT_EXPRESSION
build variable controlling what to compile: System.Linq.Expressions.Expression
or FastExpressionCompiler.LightExpression
int.TryParse