Ability to convert constructors directly into delegate types. #9829
Answered
by
ufcpp
itsBuggingMe
asked this question in
Language Ideas
-
|
It's very useful to convert from method groups directly into delegate types. Func<string, int> parseInt = int.Parse;
int[] nums = strings.Select(int.Parse).ToArray();It would also make sense to be able to do the same for constructors: // maybe something like this:
Func<Bar, Foo> ctor1 = new Foo;
Func<Bar, Foo> ctor2 = Foo::new;
Func<Bar, Foo> ctor3 = Foo.new;
record Foo(int Bar);A workaround is to just make a lambda that calls the method, e.g. This would be especially nice for serialization scenarios when you are creating delegates for object creation, such as in JsonTypeInfo, or just when populating/initialising a large number of items. |
Beta Was this translation helpful? Give feedback.
Answered by
ufcpp
Nov 18, 2025
Replies: 1 comment
-
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
itsBuggingMe
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
#674 #7415 #9256