我正在为微软代码合同使用 3.5 库
public object RetrieveById(int Id)
{
//stuff happens...
Contract.Ensures(newObject != null, "object must not be null");
return newProject;
//No error message if I move the Contract.Ensures to here
//But it isn't asserting/throwing a contract exception here either
}
我收到编译器消息:“方法‘Controller.RetrieveById(System.Int32)’中的 try 块中的错误 18 合同部分
更新:
在您的帮助下,我想通了:
- 移至顶部
检查 Contract.Result
Contract.Ensures(Contract.Result() != null, "对象不能为空");