class SomeModel
{
[Display(Name = "Quantity Required")]
public int Qty { get; set; }
[Display(Name = "Cost per Item")]
public int Cost { get; set; }
}
我正在尝试将模型映射到{ PropertyName, DisplayName }
成对列表中,但我被卡住了。
var properties
= typeof(SomeModel)
.GetProperties()
.Select(p => new
{
p.Name,
p.GetCustomAttributes(typeof(DisplayAttribute),
false).Single().ToString()
}
);
上面没有编译,我不确定它是否是正确的方法,但希望你能看到意图。任何指针?谢谢