Proposal: argument name in Func and Action #2738
Replies: 11 comments
-
I have often wanted to name the types in Dictionaries. For example: I think it wouldn't necessarily be a bad idea to be able to name type arguments in order to provide features for use of the IDE only. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
This reminds me of named members on tuples. Seems like a good idea. |
Beta Was this translation helpful? Give feedback.
-
I'd made the comment on other proposals but this only works in the narrow case where the named generic type argument is only used once for any given member or any given method signature. Delegates like public class Foo<T> {
public void M(T x, T y) { }
}
var f = new Foo<int bar>();
f.M(...) // ? |
Beta Was this translation helpful? Give feedback.
-
If this was a purely IDE thing, I don't think it matters to much. The IDE could choose to display bar for both, bar for neither. Whatever. The language just changes to allow you to put the name there. The meaning is left to the IDE to decide. |
Beta Was this translation helpful? Give feedback.
-
That feels a little weird if the language itself doesn't offer any support beyond just naming the generic type arguments. It makes the following feel really confusing: Func<int x, int y, int y> f = (x, y) => x + y;
int result = f(arg1: 2, arg2: 3); |
Beta Was this translation helpful? Give feedback.
-
@HaloFour |
Beta Was this translation helpful? Give feedback.
-
@YairHalberstadt Exactly. |
Beta Was this translation helpful? Give feedback.
-
Related to #894 |
Beta Was this translation helpful? Give feedback.
-
Also related to #883 |
Beta Was this translation helpful? Give feedback.
-
On the contrary, I even want to remove the parameter name of delegate: And the damned default value, it cause reflection doesn't respect method's default value. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Proposal: argument name in Func and Action
Currently when we write
Func<T1, T2, ...> func = (p1, p2, ...) => ...
, we get a delegate without parameter names.Therefore, when we want to invoke the delegate, IDE cannot prompt us the parameter name.
When we invoke it:
Solution
Allow argument name in Func and Action, just like what
ValueTuple<T>
did.Then when we invoke it:
The same for
Action<T, ...>
.Beta Was this translation helpful? Give feedback.
All reactions