3 ms·
I'm pretty printing. > You can also create reasonably 'generic' extension methods that will work on 'any' Enum Can you post a link or something to this, I did
by throwaway_pdp09 6y ago
I'm pretty printing.
> You can also create reasonably 'generic' extension methods that will work on 'any' Enum
Can you post a link or something to this, I didn't know it was possible and it will prove useful (even if only as an exercise).
> Enums in C# are crap compared to Java.
yessss, interesting isn't it. Some features of C# seem to be held back so as to make the next release look more attractive, do you think?
- koyote 6y agoSomething like this? https://dotnetfiddle.net/xwYCrt https://dotnetfiddle.net/xwYCrt You can also use the Enum static functions in order to get metadata on any enum. If you use attributes such as [Display("Pretty Name")] you can use that to retrieve the value from an enum.
- throwaway_pdp09 6y agoThat's an extension method, I was doing that. What's new is you can pass in any enumeration as you've used Enum as the base class. OK, I should have thought of that. Not sure it would have helped but... Now the [Display("Pretty Name")] is what I want! It apparently uses reflection, but for my app that's a very acceptable cost. I can see a few hundred LOC disappearing - thanks so much!