结合合同先决条件返回一次错误?
你好,
我想知道是否有办法将所有 Contract.Requiere 组合在一个方法中,所以说会发生这样的事情
public void MyMehod(Order var1, Cust var2)
{
Contract.Requires<ArgumentException>(var1 != null);
Contract.Requires<ArgumentException>(var2 != null);
//...
}
如果我调用 MyMehtod 以及 var1 和 < em>var2 为 null 我收到两条错误消息?
(也许这个例子不太好)但想法是,如果调用该方法,我想知道它有什么问题 那么,有谁知道是否可以合并合同以便我收到一条错误消息?
HI there
I was wondering if there is anyway to combine all Contract.Requiere in a method, so say something like this happens
public void MyMehod(Order var1, Cust var2)
{
Contract.Requires<ArgumentException>(var1 != null);
Contract.Requires<ArgumentException>(var2 != null);
//...
}
And that if I call MyMehtod and both var1 and var2 are null I get both error messages?
(maybe the example is not great) but the idea is that if call the method, I want to know everything that's wrong with it
So, does anyone know if its possible to combine the Contracts so that I get one error message back?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种非常粗鲁的方法 - 它不能扩展到很多参数 - 是首先签订一份合同,如果两者都为空,则该合同将失败:
或
...但是你仍然需要两个人那些。我不认为我会建议实际上这样做,但这是我能立即想到的唯一事情。
One really crufty way - which doesn't scale to lots of arguments - is to first have a contract which will fail if both are null:
or
... but then you'd still need the two individual ones. I don't think I'd recommend actually doing this, but it's the only thing I can think of offhand.