Allow omitting unused parameters #8802
Replies: 5 comments
-
Tagging @jcouv |
Beta Was this translation helpful? Give feedback.
-
I think permitting multiple underscores (discard) as parameter names for methods would have the same effect. For now, it is planned to permit that only for lambda parameters. |
Beta Was this translation helpful? Give feedback.
-
Relates to #111 ("Discard for lambda parameters (_, _) =>"). |
Beta Was this translation helpful? Give feedback.
-
Tagging @CyrusNajmabadi in case he wants to champion this |
Beta Was this translation helpful? Give feedback.
-
I will champion this. |
Beta Was this translation helpful? Give feedback.
-
Referring to the discussion over at the Roslyn repo (dotnet/roslyn#32851), the IDE0060 warning can be raised for unused parameters that are required to match a delegate signature. There's currently no way to indicate the intent to ignore the parameter altogether, so suggestions are to remove the parameter (not always possible), or to put a suppression in place.
It'd be nice to have a way to indicate that a parameter is required but is being ignored explicitly. The closest existing language feature seems to be the discard
_
, but it suffers from being a valid identifier already. Another option would be to follow C++'s lead to allow omitting a name altogether:Note that IDE0060 has special cases for typical event signatures, to avoid raising warnings for these. Nonetheless, there are many places where having a parameter is imposed, and there's no way to indicate not caring about it explicitly. E.g. method group conversion for delegates and events, interface implementation, overriding base members, etc.
The idea would be: if a parameter name was written down, you better use it (if not, IDE0060 results). If you explicitly don't want to use it, you can use some way to discard it (and IDE0060 can offer a code fix that performs the edit).
Design Meetings
Beta Was this translation helpful? Give feedback.
All reactions