1
可能重复:
How to determine the attached type from within a custom attribute?如何获取我的class-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;
}
}
注意与它注释的行。是否有可能获得该类属性附加到的类的类型,还是不是?
我不确定你的意思,哪个对象的类型? – Magnus