ここでは、AAtribute という名前のカスタム属性を作成しました。たとえば、1 つ以上のメソッドがこの属性を使用する B というクラスを作成しました。アセンブリ全体を調べたり、属性に対して定義されたすべてのメソッドを調べたりせずに、属性 (この場合は BMethod1) をその属性 (の 1 つ) として保持するメソッドの MethodInfo を取得することは可能ですか? そして、それらは他の AttributeTargets (パラメーター/タイプ/プロパティ/...) の類似の方法ですか? そのタイプの属性を使用するすべてのメソッドの配列は必要ありませんが、この属性オブジェクトを部分的に使用するメソッドだけが必要です。メソッドに追加の制約を設定するために使用したい (戻り値の型、パラメーター、名前、その他の属性の使用法など)。
[AttributeUsage(AttributeTargets.Method)]
public class AAtribute : Attribute {
//some fields and properties
public AAtribute () {//perhaps with some parameters
//some operations
MethodInfo mi;//acces to the MethodInfo with this Attribute
//as an Attribute (the question)
//some operations with the MethodInfo
}
//some methods
}
public class B {
//some fields, properties and constructors
[A]
public void BMethod1 () {
//some operations
}
//other methods
}