The technique of having description attributes against enum values is something I've been doing for a few years. However I just had a requirement to use this technique again, and thought it would be useful as an extension method.
1: public enum ITEMUPDATESTATUS
2: {
3: [Description("Unknown")]
4: Unknown = 0,
5: [Description("Failed validation")]
6: FailedValidation,
7: [Description("Product not found")]
8: SKUNotFound,
9: [Description("Manufacturer code doesn't exist")]
10: ManufacturerCodeNotExists
11: }
12:
13: public static class Enum<T>
14: {
15: public static string Description(T value)
16: {
17: DescriptionAttribute[] da = (DescriptionAttribute[])(typeof(T).GetField(value.ToString()).GetCustomAttributes(typeof(DescriptionAttribute), false));
18: return da.Length > 0 ? da[0].Description : value.ToString();
19: }
20: }
And then the description can be obtained by a simple syntax:
1: ITEMUPDATESTATUS i = ITEMUPDATESTATUS.FailedValidation;
2: Console.WriteLine(Enum<ITEMUPDATESTATUS>.Description(i));