Suppose your code is correct. It works, and you're just trying to get a code contract system to recognize this fact.
This means that calling CountOfItems on an instance of MyObject will always return a value greater than zero. It will not throw an exception, and it will not return a value equal to zero or less.
This means that someEnumerable will be assigned to some object, and someEnumerable.Count() will always return a value greater than zero for any object. These facts will be valid at all times (since there are no restrictions on when CountOfItems can be called.
This means that there is an invariant object (regardless of whether it is explicitly specified in the code or not) for MyObject , which includes these facts. And since your code is correct (by assumption), the MyObject implementation ensures that someEnumerable assigned, and its counter is always greater than zero.
Thus, in order to satisfy the contract for CountOfItems , the contract system must be aware of these invariants and how they are provided.
source share