I have made a custom Attribute here named AAtribute, and for instance a class called B where one or more methods use the attribute. Is it possible to get the MethodInfo of the method that holds the attribute (in this case BMethod1) as (one of) it's attributes without walking through the whole assembly and looking at all defined methods for their attributes? And is their an analogue way for other AttributeTargets (Parameters/Types/Properties/...)? I'don't want an array of all Methods that use that type of Attribute, but just the method with this Attirbute-object in particual. I want to use it to put additional constraints on the method (Return type, parameter, name, other Attribute-usage,...).
[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
}