I am intercepting the methods on an interface because I want to be sure my pre-invoke code is run for all public methods of any given implementation. I know I could do method interception, but that makes configuration harder and risks new methods in the future not getting configured.
At runtime I am able to get the implemented class from the IInvocation argument by calling GetType on invocation.Request.Target. What I can't find is how to get which method is being called.
Once I have the class type, I could probably query the method by name, but then I have to get in to querying on parameters as well in case there's overloads and I'd rather avoid that if possible.
Ultimately I am trying to pull the attributes off the calling method. So if there's a shortcut, that would work too.
EDIT: I know that I can put my attributes on the interface members (I am doing that now as a work around), but that cannot be the final solution in my case.
EDIT 2: Requested code sample:
public class PublicBusinessInterceptor : SimpleInterceptor
{
protected override void BeforeInvoke(IInvocation invocation)
{
var interfaceMemberType = invocation.Request.Target.GetType();
}
}
In the code sample above, interfaceMemberType
is, as the variable name implies, the type of the interface member. I need the type of the implemented member that is being called in this context. The implemented member type has the attributes that I need. The interface member type does not.