Reputation: 3240
How can I get information of data member (MethodInfo, PropertyInfo Etc) from the attribute is applied to it.
[Custom]
public void MethodA()
{
}
[AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
sealed class PluginInitAttribute : Attribute
{
public CustomAttribute()
{
//Get MethodA's MethodInfo here
}
}
}
Tnx ahead!
Upvotes: 1
Views: 97
Reputation: 1063519
You cannot. An attribute does not know which member it was attached to (if any). However, a member can get access to the attributes that adorn it.
Usually, the calling code (the code that checks for the attribute) would be responsible for telling the attribute about any necessary context such as this, but that is entirely implementation specific.
Upvotes: 1