【发布时间】:2016-02-10 12:22:11
【问题描述】:
我有一个类 Person 有两个属性
public sealed class Person
{
[Description("This is the first name")]
public string FirstName { get; set; }
[Description("This is the last name")]
public string LastName { get; set; }
}
在我的控制台应用程序代码中,我想为每个实例的每个属性获取描述属性的值.....
类似
Person myPerson = new Person();
myPerson.LastName.GetDescription() // method to retrieve the value of the attribute
是否有可能完成这项任务? 有人可以建议我一个方法吗? 最好的祝福 棒棒哒
【问题讨论】:
-
不使用该语法,这是不可能的。使用其他语法是可能的(如链接问题中所示)
标签: c# reflection custom-properties