How do I get description of Enum?

What you will do if you asked to get a description of your defined Enum?
Here is a simplest way, just need to define an extension method:
 
We have following defined Enum:
 
  1. public enum AuthorLevels  
  2. {  
  3.   [Description("No level")]  
  4.   None,  
  5.   Description("Starter")]  
  6.   Bronze,  
  7.   [Description("Intermediate")]  
  8.   Golden,  
  9.   [Description("Advance")]  
  10.   Platinum  
  11. }  
Define an extension method:
 
  1. public static class EnumExtensionMethods  
  2.     {  
  3.         public static string GetEnumDescription(this Enum enumValue)  
  4.         {  
  5.             var fieldInfo = enumValue.GetType().GetField(enumValue.ToString());  
  6.   
  7.             var descriptionAttributes = (DescriptionAttribute[])fieldInfo.GetCustomAttributes(typeof(DescriptionAttribute), false);  
  8.   
  9.             return descriptionAttributes.Length > 0 ? descriptionAttributes[0].Description : enumValue.ToString();  
  10.         }  
  11.     }  
Do not forget to add following namespace, in above:
 
  1. using System.ComponentModel;  
 
Now, call this extension method as:
 
  1. var authorLevel = AuthorLevels.Platinum.GetEnumDescription();  
Above will give you: 'Advance'.
 
Enjoy :)