My enum consists of the following values:
private enum PublishStatusses{
NotCompleted,
Completed,
Error
};
I want to be able to output these values in a user friendly way though.
I don't need to be able to go from string to value again.
The simplest way is just to include this extension class into your project, it will work with any enum in the project:
Usage:
...
Instead of using an enum use a static class.
replace
with
it will be used like this
Issue using the top "extension method" solutions:
A private enum is often used inside another class. The extension method solution is not valid there since it must be in it's own class. This solution can be private and embedded in another class.
I think the best (and easiest) way to solve your problem is to write an Extension-Method for your enum:
Maybe I'm missing something, but what's wrong with Enum.GetName?
edit: for user-friendly strings, you need to go through a .resource to get internationalisation/localisation done, and it would arguably be better to use a fixed key based on the enum key than a decorator attribute on the same.
The easiest solution here is to use a custom extension method (in .NET 3.5 at least - you can just convert it into a static helper method for earlier framework versions).
I am assuming here that you want to return something other than the actual name of the enum value (which you can get by simply calling ToString).
For flags enum including.