Quote:Original post by ChaosEngineQuote:Original post by itachi...
That relieves one use case of backing fields (granted if you're writing WPF/Silverlight, it's probably a large use case), but it doesn't alleviate the need for them completely.
What if you want to validate the value, for instance?
You're right, I was thinking (at least after I posted) of a more feature rich attribute that would also allow to specify custom Changing/Changed/Validate methods. Or maybe the compiler could just automatically look for methods inside that class that match a certain name and signature, so that if you have
[NotifyPropertyChanged]
public bool Blah { get; private set; }
the compiler would look for methods that match void OnBlahChanging(bool oldValue, bool newValue) and such... That, for me, would eliminate the need for backing fields in 99% of all cases. It would also be nice if it were possible to initialize the property to a certain value in that same line, something like: string Blah { get; set; } = "Hello";