Here is something that struck me, and I wonder if this is possible at all.
In short, here is the code:
public class NotificationCollection : ObservableCollection<Notification> { public NotificationCollection() : base() { this.CollectionChanged += NotificationCollection_CollectionChanged; this.PropertyChanged += NotificationCollection_PropertyChanged; } public NotificationCollection(IEnumerable<Notification> items) : base(items) { this.CollectionChanged += NotificationCollection_CollectionChanged; this.PropertyChanged += NotificationCollection_PropertyChanged; } (....) }
As you can see, I am duplicating the code. If I did not create an inherited class, I would write
public NotificationCollection(IEnumerable<Notification> items) : this() //I can just call the empty constructor { //do stuff here... //however, in case of inheritance this would be handled by base(items) }
So my question is: can I call the constructor of the base
class, as well as the constructor of this
?
source share