I was wondering if anyone had a possible solution to the following problem… I have a base class that a series of derived classes will inherit from. The base class cares about whether properties on the derived class have changed. This is to set up an “IsDirty” approach for a data transfer object.
The traditional approach would be to set an IsDirty boolean flag declared in the base class. I was hoping to avoid this somehow, and was wondering if there might be another approach? I am concerned about a developer not remembering to set the flag in the equivalent set operation on a property in the derived class. I had considered the idea of creating a generic “SetProperty” method that would take the property name and value, but thought that there might be something more elegant.
Just as a side note, ideas regarding using reflection are not a problem. Regardless of the expense of reflection, I would like to prove out a way to do it and work on refining it further on down the road.
Can you force the derived classes to implement INotifyPropertyChanged? In that case I’d add a listener to the PropertyChanged event in the base class constructur and chill. The derived class now still needs to follow the pattern (which might be something you want to avoid?).
Nice read for a “no literal strings used” approach for raising the property changed events: http://monotorrent.blogspot.com/2009/12/yet-another-inotifypropertychanged-with_06.html