【发布时间】:2011-10-15 13:58:53
【问题描述】:
有什么方法可以访问您在属性中附加属性的类和属性名称?
例如
public class User {
public string Email { get; set; }
public string FirstName { get; set; }
[MyAttribute]
public string LastName { get; set; }
}
然后在 MyAttribute 类中
public class MyAttributeAttribute {
public MyAttributeAttribute () : base() {
string className = /*GET CLASS NAME - should return "User" */
string propertyName = /*GET PROPERTY NAME - should return LastName*/
}
}
我知道我可以在构造函数中传递信息,但希望有一种简单的方法可以通过反射或...
【问题讨论】:
标签: c# reflection custom-attributes