17
class SomeModel
{
[Display(Name = "Quantity Required")]
public int Qty { get; set; }
[Display(Name = "Cost per Item")]
public int Cost { get; set; }
}
私はこのモデルを{ PropertyName, DisplayName }
のペアのリストにマップしようとしていますが、私は立ち往生しています。PropertyInfoからDisplayAttribute属性を取得
var properties
= typeof(SomeModel)
.GetProperties()
.Select(p => new
{
p.Name,
p.GetCustomAttributes(typeof(DisplayAttribute),
false).Single().ToString()
}
);
上記はコンパイルできないと私はそれがとにかく正しいアプローチだわからないんだけど、うまくいけば、あなたは意図を見ることができます。すべてのポインタ?ありがとう
完璧、ありがとうございました – fearofawhackplanet
@fearofawhackplanet、よろしくお願いします! –