In my UI code I have a lot classes with the same basic skeleton:
- derives from INotifyPropertyChanged
-
contains the following code:
void NotifyPropertyChanged(String info) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(info)); } } public event PropertyChangedEventHandler PropertyChanged;
It seems like a perfect chance to factor into a class and to derive from that instead of INotifyPropertyChanged, but sadly C# doesn’t support multiple inheritance so it’s not really going to work. Any ideas on how to refactor this kind of code?
Can’t you just put this code into your superclass’s superclass?
Most MVVM Frameworks provide such a class for you.
Because of the access rules around events, you can’t factor this out into an extension method without reflection, unfortunately.