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 に答える