【发布时间】:2011-07-09 19:56:50
【问题描述】:
可能重复:
How to determine the attached type from within a custom attribute?
我有这个自定义类属性:
[AttributeUsage(AttributeTargets.Class)]
public class ConfigurableClass : Attribute
{
public Type Control { get; private set; }
public bool IsSingleton { get; private set; }
public string Name { get; private set; }
public ConfigurableClass(bool isSingleton) : this(null, isSingleton)
{
}
public ConfigurableClass(Type control, bool isSingleton)
{
Control = control;
this.IsSingleton = isSingleton;
this.Name = ""; //set name to typename of the attached class here?
}
public ConfigurableClass(Type control, bool isSingleton, string name) : this(control, isSingleton)
{
this.Name = name;
}
}
注意其中包含注释的行。是否可以获取该类属性所附加的类的类型?
【问题讨论】:
-
我不确定你的意思,哪个对象的类型?
标签: c# reflection