C# getter and setter shorthand

If my understanding of the internal workings of this line is correct:

public int MyInt { get; set; }

Then it behind the scenes does this:

private int _MyInt { get; set; }
Public int MyInt {
    get{return _MyInt;}
    set{_MyInt = value;}
}

What I really need is:

private bool IsDirty { get; set; }

private int _MyInt { get; set; }
Public int MyInt {
    get{return _MyInt;}
    set{_MyInt = value; IsDirty = true;}
}

But I would like to write it something like:

private bool IsDirty { get; set; }

public int MyInt { get; set{this = value; IsDirty = true;} }

Which does not work. The thing is some of the objects I need to do the IsDirty on have dozens of properties and I'm hoping there is a way to use the auto getter/setter but still set IsDirty when the field is modified.

Is this possible or do I just have to resign myself to tripling the amount of code in my classes?

14
задан William 15 February 2011 в 21:36
поделиться