public static EnumMetadataDisplay ( this value ) : string | ||
value | this | 被扩展对象 |
Résultat | string |
public static string EnumMetadataDisplay(this Enum value)
{
var name = Enum.GetName(value.GetType(), value);
if (string.IsNullOrEmpty(name))
return value.ToString();
var attribute = value.GetType().GetField(name).GetCustomAttributes(
typeof (DisplayAttribute), false)
.Cast<DisplayAttribute>()
.FirstOrDefault();
if (attribute != null)
return attribute.Name;
return value.ToString();
}