Suggestion: Support Member Functions and Static Functions in C# Enumerations #8515
Unanswered
soul-soft
asked this question in
Language Ideas
Replies: 1 comment
-
See #297 |
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
-
Dear .NET Community Team,
I would like to propose a suggestion regarding the C# language, discussing the possibility of supporting member functions and static functions within enumeration types. As application requirements grow more complex, we find that enumerations need more flexible functionalities to better manage and extend related business logic.
Background
Currently, enumerations in C# are primarily used to define a fixed set of constant values. While this is sufficient for simple scenarios, we encounter limitations when dealing with logic related to enumeration values. The inability to directly include methods within enumeration types leads to less intuitive implementations, often causing reduced maintainability of the code.
Scenario Example
Consider the following scenario where I define an enumeration named FileExtensionsType, representing different file extensions.
In this example, I wish to embed both the GetImageTypes static method and the GetDescription member function directly within the enumeration, making the related logic clearer and more straightforward.
Need for Member Functions
1.Common Helper Methods: Supporting static functions like GetImageTypes within enumerations would allow for the provision of relevant helper methods, simplifying the way developers utilize that enumeration.
Beta Was this translation helpful? Give feedback.
All reactions