using System.Diagnostics.Contracts;
class C
{
public C(bool x)
{
Contract.Ensures(this.X == x); // is this necessary?
this.X = x;
}
public readonly bool X; // could be a property instead,
} // I'm just trying to keep this example simple
The point of this constructor is initializing a field, and the contract merely captures that intent. The contract has the same complexity as the code to which it applies. To me, it feels redundant, as if I had just written the same code twice (albeit from two slightly different perspectives).
Are "micro-contracts" of this kind necessary at all, or does Code Contracts infer these from the method body?