取得ロジック
public static string GetName(this Enum enm)
{
var gm = enm.GetType().GetMember(enm.ToString());
var attributes = gm[0].GetCustomAttributes(typeof(DescriptionAttribute), false);
var description = ((DescriptionAttribute)attributes[0]).Description;
return description;
}
使用例
public enum ErrorMessages
{
[Description("指定されたデータは存在しません。")]
NotFoundError,
}
//指定されたデータは存在しません。 var errorMessage = ErrorMessages.NotFoundError.GetName()