I understand that I cannot add the prerequisites for implementing the interface. I have to create a contract class where I define contracts on the elements that see the interface.
But in the following case, how can I add a contract to the internal state of the implementation, which is therefore not known at the interface definition level?
[ContractClass(typeof(IFooContract))]
interface IFoo
{
void Do(IBar bar);
}
[ContractClassFor(typeof(IFoo))]
sealed class IFooContract : IFoo
{
void IFoo.Do(IBar bar)
{
Contract.Require (bar != null);
}
}
class Foo : IFoo
{
public object MyState { get; set; }
void IFoo.Do(IBar bar)
{
<...>
}
}
source
share