/// <summary> /// Generates a list from the enum values. /// </summary> /// <param name="enumtype">The enum type.</param> /// <returns>A list with the enum values.</returns> public static List <string> GetEnumAsList(Type enumtype) { List <string> listBuilder = new List <string>(); if (FWReflectionHelper.IsNullable(enumtype)) { listBuilder.Add(string.Empty); enumtype = Nullable.GetUnderlyingType(enumtype); } foreach (var item in Enum.GetValues(enumtype)) { if (!HasAttribute <FWIgnoreAttribute>(item as Enum)) { listBuilder.Add(((int)item).ToString()); } } return(listBuilder); }
/// <summary> /// Generates a dictionary from an enum where the key is the enum string name and the value is the enum int value. /// </summary> /// <param name="enumtype">The enum type.</param> /// <returns>The dictionary generated from the enum.</returns> public static Dictionary <string, string> GetEnumAsDictonary(Type enumtype) { if (!FWReflectionHelper.IsEnum(enumtype)) { throw new FWArgumentException("enumtype"); } Dictionary <string, string> dictonaryBuilder = new Dictionary <string, string>(); //Gets the true type, whether is nullable or not. enumtype = FWReflectionHelper.GetUnderlyingType(enumtype); foreach (var item in Enum.GetValues(enumtype)) { if (!HasAttribute <FWIgnoreAttribute>(item as Enum)) { dictonaryBuilder.Add(((int)item).ToString(), item.ToString()); } } return(dictonaryBuilder); }