public object Convert(object v) { var value = (string)v; var enumType = typeof(TEnum); object res = null; foreach (var enumVal in Enum.GetValues(enumType)) { if (FrameworkExtensions.GetEnumDisplayName(enumType, enumVal).StartsWith(value, StringComparison.OrdinalIgnoreCase)) { if (res != null) { return(null); // two or more corresponding items found. in this case filter will not work } res = enumVal; } } return(res); }
public static IHtmlContent EnumAsJsMap <TEnum>(this IHtmlHelper html, bool useDisplayName = false) where TEnum : struct { return(EnumAsJsMap <TEnum>(html, v => useDisplayName ? FrameworkExtensions.GetEnumDisplayName(v) : v.ToString())); }