public static List<ListItem> LoadListForListControls<T>()
{
var type = typeof(T);
var list = new List<ListItem>();
foreach (var value in Enum.GetValues(type))
{
var enumValue = (Int32)value;
var fi = value.GetType().GetField(value.ToString());
var customAttributes =
fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
DescriptionAttribute attribute = null;
if (customAttributes.Length > 0)
attribute = (DescriptionAttribute)customAttributes[0];
var item = new ListItem
{
Text = attribute != null
? attribute.Description
: Enum.GetName(type, enumValue),
Value = (Convert.ToInt32(enumValue)).ToString()
};
list.Add(item);
}
return list;
}