Basically, I have a virtual method to propagate certain mandatory postconditions to subclasses. Here's a simplified version and the strange warnings the static checker generates (edit - my example was incomplete. It's right now):
public abstract class InitializerClass
{
protected bool _initialized
public bool IsInitialized
{
get { return _initialized; }
}
public virtual void Initialize()
{
//Warning CodeContracts: Missing precondition in an externally visible
//method. Consider adding Contract.Requires(this.IsInitialized); for
//parameter validation
Contract.Ensures(IsInitialized);
}
}
this is the other class:
public abstract class OrderingClass
{
protected bool _ordered
public bool IsOrdered
{
get { return _ordered; }
}
public override void Initialize()
{
//Message CodeContracts: Suggested assume: Contract.Assume(this.IsOrdered);
Contract.Ensures(IsOrdered);
}
}
in fact, both warnings are pointing to the closing curly brace of the methods, in the lines just bellow the Contract.Ensure calls. What's wrong with my code?