Generic version of System.Linq.Expressions.NewExpression #669
Replies: 10 comments
-
What's special about Also, I don't understand what are you trying to achieve. How is |
Beta Was this translation helpful? Give feedback.
-
id rather like a extended generic constraint, right now there is just |
Beta Was this translation helpful? Give feedback.
-
@JanEggers That's dotnet/roslyn#2206 and dotnet/roslyn#14461 (which should probably be moved to this repo). |
Beta Was this translation helpful? Give feedback.
-
@svick it was an example. It can be helpful for proxy instantiation and so on. Imagine that
So we are not able to call
It describes a constructor call. It can prove that provided lambda is constructor, not a field/variable or method/property call.
Why not but it is not required for the initial case. |
Beta Was this translation helpful? Give feedback.
-
Is this a language feature request or a library feature request? |
Beta Was this translation helpful? Give feedback.
-
@mattwar I think it's both. Implementing this would require adding a |
Beta Was this translation helpful? Give feedback.
-
Would you just add |
Beta Was this translation helpful? Give feedback.
-
The idea implies adding other expression types that can be created by lambda. NewExression<Func<StringBuilder>> ctorExpr = () => new StringBuilder("arg") or NewExression<StringBuilder> ctorExpr = () => new StringBuilder("arg") So perhaps it will make sense to add But consider |
Beta Was this translation helpful? Give feedback.
-
@svick, Shall I make a duplicate of my feature request in this repo? (dotnet/roslyn#14461) |
Beta Was this translation helpful? Give feedback.
-
@devedse Yes, I think it makes sense to move it here, see dotnet/roslyn#18002. You can use a tool like Issue Mover for GitHub to help you with that. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
When we deal with reflection/expressions/proxy we often see the methods like
Activator.CreateInstance(Type type, params object[] args)
. Butobject[] args
cannot be checked at compile-time. If there is no constructor that matches provided parameters (args) an exception will be thrown at run-time. It is a bad way in case when we clearly know which concrete parameters should be provided. For example proxy instance creation.However we can check it by using LambdaExpression.
Demo:
But since we use
LambdaExpression
there is no way to check at compile-time whether constructor call is really provided. So the following code is also valid:I would like to have
NewExpression<T>
to be able to pass compiler check if it will make sense for community.Thank you.
Beta Was this translation helpful? Give feedback.
All reactions