7

我最好用一个代码示例来展示我想要完成的事情?

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<>()

4

1 回答 1

5

Contract.OldValue应该足够了:

Contract.Ensures(this.SomeProperty == Contract.OldValue(this.SomePropety));
于 2010-01-28T12:14:13.957 回答