c# – “契约不能在试块中”是什么意思?
发布时间:2020-12-15 04:05:28 所属栏目:百科 来源:网络整理
导读:我正在使用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 i
我正在使用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 } 我收到编译器消息: 更新: 我在你的帮助下想出来了: >转到顶部 Contract.Ensures(Contract.Result()!= null,“object不能为null”); 解决方法
我可能会遗漏一些东西,但我只是看了一下这个文档:
http://msdn.microsoft.com/en-us/library/dd412865.aspx 它说:
因此,只需将Ensures调用放在方法的顶部,就不会出现任何问题. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |