【发布时间】:2017-04-21 02:32:12
【问题描述】:
这是我的枚举。
public enum ContractType
{
[Display(Name = "Permanent")]
Permanent= 1,
[Display(Name = "Part Time")]
PartTime= 2,
}
我尝试使用以下代码获取显示名称。
string x = Enum.GetName(typeof(ContractType), 2);
但它总是返回“PartTime”。其实我想得到显示属性的名称。 对于上面的例子,x 应该被分配 Part Time
我看到有些解决方案包含大量代码。这没有简单/单行的解决方案吗?
请告诉我一个方向。
【问题讨论】: