Replies: 6 comments
-
This sounds more like a BCL request than a language request. This would also be tricky... |
Beta Was this translation helpful? Give feedback.
-
Well the name of the attribute could be not important (a new one defined in mscorlib / System.Runtime could be OK too), the important thing is that should be a way to do this without the need to it "manually" anytime. |
Beta Was this translation helpful? Give feedback.
-
I think you can use a TypeConverter to achieve that. |
Beta Was this translation helpful? Give feedback.
-
The There's also the small issue of internationalization - hard coding the display strings like this might be suitable for internal software that's never used outside your organization, but for anyone who needs to deal with multiple cultures, this would be a non-starter. |
Beta Was this translation helpful? Give feedback.
-
you should check this out https://stackoverflow.com/questions/479410/enum-tostring-with-user-friendly-strings |
Beta Was this translation helpful? Give feedback.
-
if you are concerned about performance, use a dictionary like you can use string array instead of dictionary. and put strings corresponding to index of each enum member. although you should be careful to not miss any member. but |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
The enum toString() method is not a lot of useful as it returns the member name instead of a nice description, usually developer use Display(Name = "xxx")] attribute to overcome this limitation and then are forced to write a fake "toString()" method (using reflection), why this cannot be done inside Enum.toString() method itself?
For example:
Beta Was this translation helpful? Give feedback.
All reactions