dotnet/runtime

ReadOnlyObservableCollection.CollectionChanged should be made public

开放

#14,267 创建于 2015年2月20日

 (14 条评论) (13 个反应) (0 位负责人)C# (5,445 个派生)batch import
api-needs-workarea-System.Collectionshelp wantedwishlist

仓库指标

星标
 (17,886 个星标)
PR 合并指标
 (平均合并 12天 11小时) (30 天内合并 661 个 PR)

描述

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.

贡献者指南