public static IEnumerable <EnumDataSourceItem> BindToEnumShortNames(Type enumType, ItemsListOrder order) { List <EnumDataSourceItem> items = new List <EnumDataSourceItem>(); // get the names from the enumeration string[] names = Enum.GetNames(enumType); // get the values from the enumeration Array values = Enum.GetValues(enumType); for (int i = 0; i < names.Length; i++) { EnumDataSourceItem item = new EnumDataSourceItem(); item.value = (int)values.GetValue(i); item.key = names[i]; //item.key = EnumDescription((Enum)values.GetValue(i)); items.Add(item); } if (order == ItemsListOrder.ByValue) { var returnList = from i in items orderby i.value select i; return(returnList); } else // sort by key { var returnList = from i in items orderby i.key select i; return(returnList); } }
public static IEnumerable<EnumDataSourceItem> BindToEnumShortNames(Type enumType, ItemsListOrder order) { List<EnumDataSourceItem> items = new List<EnumDataSourceItem>(); // get the names from the enumeration string[] names = Enum.GetNames(enumType); // get the values from the enumeration Array values = Enum.GetValues(enumType); for (int i = 0; i < names.Length; i++) { EnumDataSourceItem item = new EnumDataSourceItem(); item.value = (int)values.GetValue(i); item.key = names[i]; //item.key = EnumDescription((Enum)values.GetValue(i)); items.Add(item); } if (order == ItemsListOrder.ByValue) { var returnList = from i in items orderby i.value select i; return returnList; } else // sort by key { var returnList = from i in items orderby i.key select i; return returnList; } }