I'm playing around with Microsoft's CodeContracts and encountered a problem I was unable to solve. I've got a class with two constructors:
public Foo (public float f) {
Contracts.Require(f > 0);
}
public Foo (int i)
: this ((float)i)
{}
The example is simplified. I don't know how to check the second constructor's f
for being > 0. Is this even possible with Contracts?
You can just add the precondition to the second constructor's body.
EDIT
Try calling the code above with:
You will see that the precondition is thrown before the regular Exception is thrown.