How do I set the exception property for cleanliness?

I have a class like below and I only want to change x

in the method Foo

and no other property. I cannot use [Pure]

as in the following example because it blocks all properties:

public class Test
{
    private int x,y,z; //number of these properties is large

    [Pure]
    public void Foo()
    {
        //only x must be allowed to change
    }
}

      

and I don't want to use something like this for all other properties except x

:

Contract.Ensures(Contract.OldValue<int>(y) == y);
Contract.Ensures(Contract.OldValue<int>(z) == z);
...//and for other large number of properties

      

Is there a way to do this?

+3


source to share


2 answers


Unfortunately, Contracts

I haven't found a standard way .

But you can use this way (it has some limitations):



    public class Test
    {
        public int x, y, z;//....

        public void Foo()
        {
            x = FooBody();
        }

        [Pure]
        private int FooBody()
        {
            int value = x;
            //work with value as x
            return value;
        }
    }

      

+1


source


There seems to be no method used in this class Contract

.



0


source







All Articles