public static IEnumerable <EnumDataSourceItem> BindToEnum(Type enumType, bool sortList) { 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)); item.isPrivate = EnumIsPrivate((Enum)values.GetValue(i)); items.Add(item); } if (!sortList) { //return items; var returnList = from i in items select i; return(returnList); } else // sort by value { //var returnList = from i in items orderby i.key select i; 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); } }
public static IEnumerable <EnumDataSourceItem> GetItemListByDescription(Type enumType, ListItemSortType sortType) { 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 = DevelopmentBase.Common.EnumDescription((Enum)values.GetValue(i)); item.isPrivate = DevelopmentBase.Common.EnumIsPrivate((Enum)values.GetValue(i)); items.Add(item); } if (sortType == ListItemSortType.ByTextIncreasing) { var returnList = from i in items orderby i.key ascending select i; return(returnList); } else if (sortType == ListItemSortType.ByTextDecreasing) { var returnList = from i in items orderby i.key descending select i; return(returnList); } else if (sortType == ListItemSortType.ByValueIncreasing) { var returnList = from i in items orderby i.key ascending select i; return(returnList); } else if (sortType == ListItemSortType.ByValueDecreasing) { var returnList = from i in items orderby i.key descending select i; return(returnList); } else { var returnList = from i in items 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; } }
public static IEnumerable<EnumDataSourceItem> BindToEnum(Type enumType, bool sortList) { 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)); item.isPrivate = EnumIsPrivate((Enum)values.GetValue(i)); items.Add(item); } if (!sortList) { //return items; var returnList = from i in items select i; return returnList; } else // sort by value { //var returnList = from i in items orderby i.key select i; var returnList = from i in items orderby i.key select i; return returnList; } }