public static Class Enumextention
{
<summary>
Gets the description information for the enumeration
</summary>
<typeparam name= "T" ></typeparam>
<returns></returns>
public static Dictionary<int, string> getdescription<t> ()
Where T:struct, IComparable, IFormattable, iconvertible
{
var t = typeof (T);
if (t.isenum)
{
Dictionary<int, string> list = new Dictionary<int, string> ();
Array a = enum.getvalues (t);
for (int i = 0; i < a.length; i++)
{
String enumname = A.getvalue (i). ToString ();
int enumkey = (int) System.Enum.Parse (t, enumname);
String enumdescription = GetDescription (t, EnumKey);
List. ADD (EnumKey, enumdescription);
}
return list;
}
return null;
}
#region Tool Functions
private static string GetName (System.Type T, Object v)
{
Try
{
Return Enum.getname (t, v);
}
Catch
{
return "UNKNOWN";
}
}
<summary>
Returns a description of the specified value for the specified enumeration type
</summary>
<param name= "T" > Enum type </param>
<param name= "V" > Enumeration value </param>
<returns></returns>
private static string GetDescription (System.Type T, Object v)
{
Try
{
FieldInfo fi = T.getfield (GetName (t, v));
descriptionattribute[] attributes = (descriptionattribute[]) fi. GetCustomAttributes (typeof (DescriptionAttribute), false);
return (attributes. Length > 0)? Attributes[0]. Description:getname (t, v);
}
Catch
{
return "UNKNOWN";
}
}
#endregion
}
Gets the expansion method of the enum.