使用反射获取对象中属性的值

时间:2014-07-10 11:41:13

标签: reflection attributes

例如,您的对象如下:

public class Test{

[Display("**hello world**")]
public string property{}
}
}

何我使用反射来获取我的属性(显示)的值,这将返回" hello world"

1 个答案:

答案 0 :(得分:0)

我发现答案不知道它是否是最佳解决方案?

Type t = typeof(T);
var value = t.GetProperties().Select(f=>f.GetCustomAttribute<NamOfAttribute>()).DisplayName
相关问题