Been a long time since I posted on here!
I am trying to get to grip with code contracts on interfaces. Here's some example code
The problem is that the Code Contracts analyser (or whatever it is called) reports a warning 'CodeContracts: Detected call to method 'Scratch.ITest.Count' without [Pure] in contracts of method 'Scratch.TextContract.Remove(System.Int32)'Code:using System.Diagnostics.Contracts; namespace Scratch { [ContractClass(typeof(TestContract))] public interface ITest { void Add(int Number); void Remove(int Index); int Count(); } [ContractClassFor(typeof(ITest))] public abstract class TestContract : ITest { public void Add(int Number) { throw new System.NotImplementedException(); } public void Remove(int Index) { Contract.Requires(Index >= 0); Contract.Requires(Index <= this.Count()); } [Pure] public int Count() { throw new System.NotImplementedException(); } } }
I realise that the code contract class is abstract and thus will have no instances, so the question is how do I achieve this?
Thanks,
Y




Reply With Quote