sklose / NCalc2

expression evaluator for .NET with built-in compiler
MIT License
166 stars 58 forks source link

Expose intermediate System.Linq.Expressions.Expression from ToLambda() as public function #92

Closed eugenca closed 5 months ago

eugenca commented 5 months ago

see https://github.com/sklose/NCalc2/issues/89

eugenca commented 5 months ago

Not sure what to do with tuple returning error

david-brink-talogy commented 5 months ago

This might be better on #89, but a different (though not necessarily better) approach might be to open up Expression for extension. You mentioned that the goal was to optimize the compiled expression. If ToLambda was virtual, you'd have been able to override it without changing the public interface of Expression. You'd still probably want your ToLambdaExpression, but it could be protected rather than public.

something like:

public class OptimizedExpression : Expression {
  public override Func<TResult> ToLambda<TResult>() => Optimize<TResult>(ToLambdaExpression<TResult>());
  //Optimize() {}
}
eugenca commented 5 months ago

If this is important to not change public interface, I could make it this way

sklose commented 5 months ago

I like @david-brink-talogy idea, let's go with the protected method. That'll make the API less confusing for people who are not looking for this feature.

eugenca commented 5 months ago

Done, please review

eugenca commented 5 months ago

Resolved all changes