Decorating enum values

Sometimes it is useful to add properties to enum values. Translations or mapping are typical use cases. Here is how this could be accomplished.

Create an Attribute:


Decorate some enum values:


And finally apply some reflection magic:


As you can see the magic is placed inside an extension method, this way you get a nice syntax:

That’s it. Cheers!

Author: Peter

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.