CodeContracts: How to fullfill Require in Ctor using this() call?

Posted by mafutrct on Stack Overflow See other posts from Stack Overflow or by mafutrct
Published on 2009-07-23T09:57:21Z Indexed on 2010/06/18 12:23 UTC
Read the original article Hit count: 164

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?

© Stack Overflow or respective owner

Related posts about c#

Related posts about constructor