代码契约:如何在后置条件中声明字段/属性的值未更改?
我最好用代码示例来展示我想完成什么?
class SomeClass
{
public int SomeProperty;
public void SomeOperation()
{
Contract.Ensures( "SomeProperty's value has not changed." );
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// How can I write this post-condition?
}
};
(传递给 Contract.Ensures()
的字符串当然只是真正后置条件表达式的占位符。)
我该怎么做? Contract.OldValue<>()
在这里有什么用处吗?
I'll best just show with a code example what I would like to accomplish?
class SomeClass
{
public int SomeProperty;
public void SomeOperation()
{
Contract.Ensures( "SomeProperty's value has not changed." );
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// How can I write this post-condition?
}
};
(The string passed to Contract.Ensures()
is of course just a placeholder for the real post-condition expression.)
How can I do this? Would Contract.OldValue<>()
be of any use here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Contract.OldValue
应该足够了:Contract.OldValue
should be enough: