dotnet / dotNext

Next generation API for .NET
https://dotnet.github.io/dotNext/
MIT License
1.6k stars 119 forks source link

Make LexicalScope public #71

Closed koliyo closed 3 years ago

koliyo commented 3 years ago

I understand wanting to keep LexicalScope an internal implementation detail.

But allowing adding statements manually instead of using CodeGenerator would be really helpful when there is a lot of existing code using standard System.Linq.Expressions patterns.

If I could manually call LexicalScope.Current.AddStatement, it would save me a lot of code rewriting. And make gradual migrations to the dotNext LinqEx handling.

Preferably I would like to be able to do the following:

  1. Create a LexicalScope/AsyncLambdaExpression using manually specified ParameterExpression[], instead of just System.Type[]
  2. Be able to manually construct the LexicalScope, specifically using ILexicalScope.AddStatement
sakno commented 3 years ago

Hi @koliyo ,

  1. Yes, I can add support of ParameterExpression[] for AsyncLambdaExpression and LambdaExpression
  2. LexicalScope is really internal thing. It is tightly coupled with thread-local storage to follow the natural flow of instructions. Leakage of this abstraction can cause unpredictable behavior. For instance, you will save the reference to the scope and share it with another thread or reuse after construction. But I can add public static CodeGenerator.AddStatement method for the convenience.
sakno commented 3 years ago

Also, could you please provide minimal example in C# for what you expected from new API?

sakno commented 3 years ago

I'm closing issue because Statement static method has been added to release 3.3.0 and no additional feedback was received. @koliyo feel free to reopen this issue if you have a concrete suggestion about API design.