More on proxies and additional interfaces

One more thing I mentioned in the 11th part of the Dynamic Proxy tutorial, was that I think behavior of class proxy when the class implements the additional interfaces was a result of an omission, and that it’s a bug.

The issue was raised by Kenneth Xu actually roughly by the same time,on the Rhino Mocks discussion group. Anyway, this is now fixed in the trunk, and will be in version 2.2.

There’s just one thing to be aware of – you will get the old behavior (no target) for members that are implemented explicitly. This is the result of the fact that you can’t call explicitly implemented interface members on the base class, from the inherited class, when the inherited class implements the interface as well. In other words, you can’t do this:

(base as IFoo).FooMethod();

Also be aware that when you create a proxy and call:

proxy.FooMethod();

the call won’t get intercepted, if the FooMethod is not virtual. To get the required behavior, you’d have to do this:

(proxy as IFoo).FooMethod();

That is just how implementing same interfaces multiple times in the inheritance hierarchy works.

Technorati Tags: ,