I have used ObservableCollection for DataBinding in my WPF application where I am binding the collection to DataGrids and ComboBoxes. And due to a requirement, where I needed to remove objects from the collection based on a condition, I implemented the RemoveAll functionality, like List, using Extension method.
This posts specifies a few merits of Inheritance over Extension methods but is not very specific for my case as this was the only method I needed to add and I don’t intend to add another Extension method for the Collection.
I would like to know if it would be better for me to have this implemented as Extension method as is or should I think about inheriting the class and add it as a Instance method?
Also, I would like to know if there is any performance difference between the two as it has not been discussed in the mentioned post.
For the sake of one method I would use an Extension Method. In this instance it would mean your code can continue to use
ObservableCollection<T>without needing to maintain a custom type.Extension methods simply boil down to static method calls when compiled, so I can’t imagine performance is any worse than with inheritance. If anything it should be the same or better.
Personal preference is usually what drives the choice of extension methods.