2011-07-09 2 views
1

可能性の重複:クラス属性が設定されているクラスのタイプを取得するにはどうすればよいですか?

[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; 
    } 

} 

お知らせそれにコメントして行:
How to determine the attached type from within a custom attribute?

私はこのカスタムクラス属性を持っています。このクラス属性が添付されているクラスの型を取得することは可能ですか、そうではありませんか?

+0

私はあなたが何を意味しているのかわかりません、どのオブジェクトのタイプですか? – Magnus

答えて

3

これは不可能ですが、恐れ入りますが、クラスから属性を読み取るコードは、どのクラスを読み込んでいるのかわかります。だから、あなたがそのクラス名で何をする必要があれば、そこで行われるべきです。

関連する問題