【发布时间】:2015-02-19 15:04:26
【问题描述】:
我创建了一个自定义属性,我想在其中访问自定义属性属性的声明类。
例如:
public class Dec
{
[MyCustomAttribute]
public string Bar {get;set;}
}
在这里,我想(在 MyCustomAttribute 的 cass 中)获取声明类的类型(Dec)。 这有可能吗?
编辑:感谢大家的回复。我今天学到了一些新东西。
【问题讨论】:
-
你知道属性只有在你请求的时候才会被实例化,对吧?参见例如:stackoverflow.com/questions/12196647/…,所以当你实例化它们时,你清楚地知道父类的类型(因为你必须这样做
type.GetCustomAttributes())
标签: c# reflection annotations