开发者

Is there a generic interface wrapper framework

Is there a framework or a native way in .net to dynamically generate wrappers for specified interface. I need a way to say, here is a type I have and here is the interface I want to wrap around it, and for each method it the interface forward calls to these methods on the type开发者_运维知识库 provided.


If you want to do this at runtime, Castle DynamicProxy has a CreateInterfaceProxyWithoutTarget API that will do what you're asking. I believe LinFu has something similar.


ReSharper can generate this sort of code for you. Just create a member field or property of the interface type, right-click, use "ReSharper->Code->Generate", then choose "Delegating members".

It will generate members for each of the members of the interface, all of which will delegate through the member property you selected.


With .net 4.0 ImpromptuInterface can do this. It uses the DLR to forward it's method invocation from a proxy generated based on the interface.

impromptu-interface http://code.google.com/p/impromptu-interface/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜