Contract classes and nested types within interfaces
I’ve just been going through some feedback for the draft copy of the second edition of C# in Depth. In the contracts section, I have an example like this: [ContractClass(typeof(ICaseConverterContracts))] public interface ICaseConverter { string Convert(string text); } [ContractClassFor(typeof(ICaseConverter))] internal class ICaseConverterContracts : ICaseConverter { string ICaseConverter.Convert(string text) { Contract.Requires(text != null); Contract.Ensures(Contract.Result<string>() != null); return default(string); } private ICaseConverterContracts() {} } public class InvariantUpperCaseFormatter : ICaseConverter { public string Convert(string text) { return text.ToUpperInvariant(); } } The point is to demonstrate how contracts can be specified for interfaces, and then applied automatically … Continue reading Contract classes and nested types within interfaces