using System; using System.Collections.Generic; using System.ComponentModel; using System.Reflection; namespace Common.Extension { public static class EnumExtension { public static IList GetItems(this Type enumType) { if (!enumType.IsEnum) throw new InvalidOperationException(); IList list = new List(); Type typeDescription = typeof(DescriptionAttribute); FieldInfo[] fields = enumType.GetFields(); string text; foreach (FieldInfo field in fields) { if (!field.FieldType.IsEnum) continue; int value = (int)enumType.InvokeMember(field.Name, BindingFlags.GetField, null, null, null); object[] array = field.GetCustomAttributes(typeDescription, false); text = array.Length > 0 ? ((DescriptionAttribute)array[0]).Description : field.Name; list.Add(new { Value = value, Text = text }); } return list; } } }