private static MemberInfo GetEnumValueMemberInfo(CountryEnum.Countries country) { var enumType = typeof(CountryEnum.Countries); var memberInfo = enumType.GetMember(enumType.GetEnumName(country)); return(memberInfo.FirstOrDefault(m => m.DeclaringType == enumType)); }
public static string LongCountryName(this IHtmlHelper helper, CountryEnum.Countries country) { var enumValueMemberInfo = GetEnumValueMemberInfo(country); var valueAttribute = enumValueMemberInfo.GetCustomAttribute(typeof(LongNameAttribute), false); return(valueAttribute != null?valueAttribute.ToString() : country.ToString()); }