I can write such beatiful straightforward code:
public int Delta { get; private set; }
Now I want to add just one call OnPropertyChanged("Delta");
This is the only way I know how to do that:
public int Delta { get { return _delta; } private set
{
_delta = value; OnPropertyChanged("Delta"); }
}
private int _delta;
It’s too much extra-code! Why should I introduce field in this case? Can you make this code shorter? I would like to have something like that, but it doesn’t work:
public int Delta { get; private set { OnPropertyChanged("Delta"); } }
No you cannot do this with auto-properties. Auto-properties are meant to be short hand syntax for a property over a field. They have virtually no other capabilities. Any custom code execution requires a full fledged property.