.NET 4.0 interface code contracts function violation to achieve MixIns functionality

.NET 4.0 has a new "Code Contract" feature. It also works with interfaces as described here (scroll down to anywhere in the comments):

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

Now I'm wondering if we can use and abuse this "default interface implementation" feature by adding additional custom code to these contract classes to achieve some MixIns functionality?

+2


source to share


1 answer


I do not think so. When defining code contracts for an interface, you can add a rela class that contains "requires" and "provides" method calls to be added to the implementation methods, but the rewriting code will only work after the compiler has done its job (i.e. that the interface method is not implemented by the class ...)

There can be abuses to implement aspects though :-)



Anyway, I don't think the rewriting code would add anything more than what the method requires and provides. And the code will not be added to the release build, only on the debug build.

+2


source







All Articles