Enforcing nameof Usage with [MandatoryNameof] Attribute #8002
Unanswered
2Xpro-pop
asked this question in
Language Ideas
Replies: 1 comment
-
This does not need any language change. It is already possible for you to create such an attribute today and then check it with an analyzer you write :-) This is a core example of the type of scenario analyzers set out to provide a solution for :-) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I’d like to discuss a proposal for a new attribute called [MandatoryNameof], aimed at enhancing code safety and readability. This attribute ensures the use of nameof for method parameters, reducing the reliance on magic strings.
The Proposal
Introduce [MandatoryNameof], an attribute to enforce compile-time checks for nameof usage:
How It Works
Example Use Case
This enforces that eventName must be the name of an event defined in the MyEvents class.
Beta Was this translation helpful? Give feedback.
All reactions