合同可能有条件吗? [英] possible to Contract.Requires conditionally?

查看:78
本文介绍了合同可能有条件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如。我的对象可以包含一个null子obj。如果子obj不为null,我想对子obj成员进行Contract.Requires 我可以使用一个单独的函数对所有子子obj进行编码,例如:

eg. my object can contain a null child obj. I want to Contract.Requires on child obj member if the child obj is not null. Curently I use a separate function to code contract all sub child objs, such as:

if(parent.child!= null)

if (parent.child != null)

ContractValidateChild( parent.child)&NBSP; < - 然后与孩子签订合同 那里

ContractValidateChild(parent.child)  <-- and then do contract on child there

只是想知道是否有直接的方法吗?

Just wonder if there is a direct way to do it?

推荐答案

我不确定我理解你的问题,但看起来好像你问的是
逻辑含义

I'm not sure that I understand your question, but it seems like you're asking about logical implications.


Contract.Requires(parent.Child == null || IsValid(parent.Child));


这篇关于合同可能有条件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆