Finding the implementing class for an Interface

Nov 11, 2009 at 11:28 AM

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 2:40 AM

It's in the input.Target property.


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.

Nov 14, 2009 at 8:12 AM

input.Target returns "DynamicModule.ns.Wrapped_ICustomerService_a684e54fd0f3492391617fc6facd6ebf"

Nov 14, 2009 at 8:37 PM

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


Nov 15, 2009 at 2:57 AM

Great! Thanks for your help.

Nov 20, 2009 at 11:35 AM

Any developments on this yet?

Nov 26, 2009 at 6: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 10:54 AM

Yeah tried that.

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


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