[NoBrainer] Code Contracts in Interfaces with abstract base classes will not trigger if override is not specified

Today I ran into a problem when all of a sudden my code contracts stopped working – as it seemed. In reality I was missing a simple override in the implementation of a class that derived from a base class. But now for a a concrete example. Suppose you have the following scenario: ContractClassForIArbitraryObject this […]

Code Contracts in Interfaces are evaluated after Contracts in Class Implementations

I recently noticed an — at least for me — unexpected behaviour when working with Code Contracts in interfaces. When you define a contract for an interface (via ContractClassFor) and implement a class from that interface that contract is certainly enforced. However when you define additional requirements on that implementation class these contracts are evaluated […]

C# Code Contracts and Interface Properties

I recently ran into a problem when trying to use Code Contracts on Auto-Implemented Properties (i.e. Automatic Properties) combined with a C# interface. I started with a normal interface IScriptInvokerImpl where I wanted to define a method for running a PowerShell script and a public property for the PowerShell instance being used: A first implementation […]