ここではAAtributeという名前のカスタム属性を作成しました。たとえば、Bという名前のクラスがあります。この属性(この場合はBMethod1)を保持するメソッドのMethodInfoを、アセンブリ全体を歩き回ることなく、属性に定義されたすべてのメソッドを調べることなく(属性の1つとして)取得することは可能ですか?他のAttributeTargets(パラメータ/タイプ/プロパティ/ ...)のための彼らのアナログ方法ですか?このタイプのAttributeを使用するすべてのメソッドの配列が必要ではありませんが、このAttirbuteオブジェクトを持つメソッドだけが特定のものになります。私はメソッド(戻り値の型、パラメータ、名前、他の属性の使用法、...)に追加の制約を加えるために、このメソッドを使いたい。C#の属性を保持する型/メソッド/ ...への高速アクセス
[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
}
良い質問ですが、私も答えを知りたいのですが... –