.NET Framework 接口合同
示例
使用代码合同,可以将合同应用于接口。这是通过声明一个实现接口的抽象类来完成的。接口应使用标记,ContractClassAttribute合同定义(抽象类)应使用标记。ContractClassForAttribute
C#示例...
[ContractClass(typeof(MyInterfaceContract))]
public interface IMyInterface
{
string DoWork(string input);
}
//切勿继承此合同定义类
[ContractClassFor(typeof(IMyInterface))]
internal abstract class MyInterfaceContract : IMyInterface
{
private MyInterfaceContract() { }
public string DoWork(string input)
{
Contract.Requires(!string.IsNullOrEmpty(input));
Contract.Ensures(!string.IsNullOrEmpty(Contract.Result<string>()));
throw new NotSupportedException();
}
}
public class MyInterfaceImplmentation : IMyInterface
{
public string DoWork(string input)
{
return input;
}
}静态分析结果...
热门推荐
10 元旦祝福语 简短独特群发
11 学校元旦祝福语和简短
12 送给老婆祝福语简短大全
13 牛年大气简短的祝福语
14 孩子满月红包祝福语简短
15 祝女儿结婚简短祝福语
16 兄弟生日恶搞祝福语简短
17 婆婆去世的祝福语简短
18 商务感恩祝福语大全简短