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