views:

366

answers:

1

.NET 4.0 has that new Code Contracts feature. It works with interfaces too, as described here (scroll down to somewhere in the comments):

http://weblogs.asp.net/podwysocki/archive/2008/11/08/code-contracts-for-net-4-0-spec-comes-alive.aspx

Now my question is, can we use and abuse this "Default Interface Implementation Feature" by putting more custom code into those contract classes to achieve some MixIns functionality?

+1  A: 

I don't think so. When defining code contracts for an interface, you can add a rela class that contains "requires" and "ensures" method calls that will be added to implementation methods, but the code rewriter will only run after the compiler has done its job (ie complaining that the interface method is not implemented by the class...)

Might be abused to implement aspects, though :-)

Anyway, I don't think the code rewriter would add anything else than requires and ensures method. And the code would not be added to the release assembly, only on the debug assembly.

Stephan Leclercq
wooh that took a while until someone answered ... okay if it's a debug build feature only then it's obviously bummer ... i'm gonna look for another route, thank you.
herzmeister der welten