62,270
社区成员
发帖
与我相关
我的任务
分享
public class Test
{
[DisplayName("AAA")]
public string Name { get; set; }
}
if (ma1.DisplayName.Equals("AAA"))
{
PropertyInfo piInstance =
typeof(TestModel).GetProperty(f1.Name);
piInstance.SetValue(st, "123", null);
}
Type clsType = typeof(Test);
MemberInfo f1 = clsType.GetMember("Name")[0]; //这里省略循环,判断等过程
DisplayNameAttribute ma1 = (DisplayNameAttribute)Attribute.GetCustomAttribute(f1, typeof(System.ComponentModel.DisplayNameAttribute));
string dspval = ma1.DisplayName;
public class Test
{
private string _name;
[DisplayName("AAA")]
public string Name
{
get
{
if (_name == null)
_name = this.GetType().GetProperty("Name").GetCustomAttribute<DisplayNameAttribute>().DisplayName;
return _name;
}
}
}