dotnet/runtime

ReadOnlyObservableCollection.CollectionChanged should be made public

Open

#14.267 aperta il 20 feb 2015

Vedi su GitHub
 (14 commenti) (13 reazioni) (0 assegnatari)C# (5445 fork)batch import
api-needs-workarea-System.Collectionshelp wantedwishlist

Metriche repository

Star
 (17.886 star)
Metriche merge PR
 (Merge medio 12g 11h) (661 PR mergiate in 30 g)

Descrizione

The ReadOnlyObservableCollection.CollectionChanged event is protected, which is flawed, it prevents you from being able to observe changes to it without casting to INotifyCollectionChanged.

I suspect the original thinking was because the collection is "read-only" it never changes - this is not correct. Read-only in .NET means that the consumer has a read-only view over a collection (which is why we project IReadOnlyList<T> to IVectorView<T>), not that the contents are immutable and never change.

While we've made protected members public in the past (such as Exception.HResult), this event was marked virtual, which while binary compatible, would be a source-breaking change for those that overrode it. I suspect very little have overridden it, but we may want to consider adding a new event with a different name such as Changed.

Guida contributor