[Proposal]: Simplify Enum Value Access #8909
-
SummaryAllow enum values to be referenced without requiring the enum type's prefix (e.g., SomeValue instead of SomeEnum.SomeValue) in contexts where the type is already implied or inferred. MotivationCurrently, enum values must always be prefixed by their enum type, even when the type is clear from the context. This results in verbose, redundant code and reduces readability. Current Example:
Proposed Usage:
This change would make code cleaner and improve developer productivity, especially in enum-heavy scenarios. Proposed SolutionEnable context-sensitive access to enum values, where the type can be inferred from the current scope (e.g., method parameters, variables, or properties). Why Not Static Imports?Static imports (using static SomeEnum;) are often suggested as a solution but are not ideal because:
These issues make static imports unsuitable for simplifying enum usage in a safe and scalable way. Benefits
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Dupe of #2926 |
Beta Was this translation helpful? Give feedback.
Dupe of #2926