Suggestion: Add Func<> to compile expressions to configuration
schuettecarsten opened this issue · comments
I heavily use a forked version of FastExpressionCompiler in my project, and so I think it would be great if Stashbox also use this library when compiling expressions. For that, I have changed the ExpressionExtensions like this:
@@ -36,15 +34,18 @@ namespace System.Linq.Expressions
resolutionContext.SingleInstructions.Add(expression);
expression = Expression.Block(resolutionContext.DefinedVariables.WalkOnValues(), resolutionContext.SingleInstructions);
}
if (containerConfiguration.ForceUseMicrosoftExpressionCompiler)
return Expression.Lambda<Func<IResolutionScope, object>>(expression, resolutionContext.CurrentScopeParameter).Compile();
#if IL_EMIT
if (!expression.TryEmit(out Delegate factory, typeof(Func<IResolutionScope, object>), typeof(object),
resolutionContext.CurrentScopeParameter))
factory = Expression.Lambda(expression, resolutionContext.CurrentScopeParameter).CompileFast();
return (Func<IResolutionScope, object>)factory;
#else
return Expression.Lambda<Func<IResolutionScope, object>>(expression, resolutionContext.CurrentScopeParameter).CompileFast();
#endif
}
Take a look at schuettecarsten@85023aa for details.
Of course, I cannot expect that you will include this library into the project, but maybe you can add a Func<LambdaExpression, Delegate> parameter to the configuration to allow usage of external expression compilers?
Sure, I have added the option in the latest pre-release package. What do you think?
Great, thank you! 👍