Finding the implementing class for an Interface

Nov 11, 2009 at 12:28 PM

I've been playing around with Unity to do some AOP stuff, and inside the...


IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)

...method of the ICallHandler i want to access the namespace, method and class that is the source of the handler invocation.
I can get the method via "input.MethodBase.Name" and via "input.MethodBase.DeclaringType.Name" gets me the Interface on which the method is defined... but how could i get access to the class which implemented the interface and which is actually doing the work?

eg: if i had the following... how would i get "CustomerService"?

namespace Thing

    public class CustomerService : ICustomerService
        public void DoSomething()
        { }


Nov 12, 2009 at 3:40 AM

It's in the input.Target property.


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.

Nov 14, 2009 at 9:12 AM

input.Target returns "DynamicModule.ns.Wrapped_ICustomerService_a684e54fd0f3492391617fc6facd6ebf"

Nov 14, 2009 at 9:37 PM

Really? Hrm, that could be a bug. I'll check it out.


Nov 15, 2009 at 3:57 AM

Great! Thanks for your help.

Nov 20, 2009 at 12:35 PM

Any developments on this yet?

Nov 26, 2009 at 7:26 PM

Target is supposed to be the actual target object that's being intercepted. But to answer you actual question, have you tried input.MethodBase.ReflectedType?


Nov 30, 2009 at 11:54 AM

Yeah tried that.

input.MethodBase.ReflectedType.Name gives back the interface ICustomerService.


Dec 1, 2009 at 7:53 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.