开发者

Composition/Delegation in C#

Okay, I need to use some third party library and the resulting code is hard to unit test, because the classes don't implement interfaces (i.e. I can't isolate my code from the dependencies it has on theirs, which in turn relies on databases and who knows what else).

My solution - wrap the third party classes in my own classes which have the same interface and contain an instance of the third party class. Easy enough, so far.

Question: is there any way to automagically extract those interfaces from the existing (third party) classes? It seems like I am going to be writing a lot of boil开发者_运维技巧er plate code if I do it manually.


I don't know of a tool that does that exactly. But, the way I would do it is this. Take Reflector and reverse engineer the third party component. Take the code and "smash it down" to just method signatures. Then, with a small amount of tweaking, you have an interface. Not completely "no boilerplate", but it does remove a lot of the rote work.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜