>>T[] enumValues = (T[])Enum.GetValues(typeof(T)); >> string[] enumNames = (string[])Enum.GetNames(typeof(T)); >> >> for (int i = 0; i < enumValues.Length; i++) >> { >> bool selected = false; >> object enumUnderlyingValue = Convert.ChangeType(enumValues[i], enumUnderlyingType); >> >> if (omitEnumValue != null && enumUnderlyingValue.Equals(omitUnderlyingValue)) >> { >> // The Enum value matches the omitValue parameter, so we won't process it. >> // This check is for enums that have a default value such as NotSpecified >> // which we may not always want to include in a dropdown. >> } >> else >> { >> Int32 enumValue = Convert.ToInt32(enumUnderlyingValue); >> string enumName = GetFormattedEnumName<T>(enumNames[i]); >> >> if (selectedUnderlyingValue != null) >> { >> selected = enumUnderlyingValue.Equals(selectedUnderlyingValue) ? true : false; >> } >> >> items.Add(GetNewSelectViewModel(selected, enumName, enumValue)); >> } >> }>>
>> public enum LookupTypes : byte >> { >> [Description("Select Lookup Method")] >> Typing = 1, >> HotKeySelect = 2, >> SingleKeyLookup = 3, >> MultiKeyLookup = 4 >> } >>}>>
>> var lookupTypes = EnumUtilities.EnumToEnumViewModel<LookupTypes>(selectEnumValue: LookupTypes.Typing);>>
string enumName = GetFormattedEnumName<T>(enumNames[i]);
This function, it turn, did the followingprivate static string GetFormattedEnumName<T>(string enumName) { // If the enum value has a Description attribute then use // the Description property of that attribute for the // enum name. Otherwise, split the enum name on its // camel casing and use that for the name. string formattedEnumName = GetEnumDescription<T>(enumName); if (formattedEnumName == null) { formattedEnumName = SplitCamelCase(enumName); } return formattedEnumName; }BTW, do you see a reason of having this function static?