Skip to content

src/Common/src/CoreLib/System/Collections/ObjectModel/ReadOnlyCollection.cs design failures #31557

@deep-outcome

Description

@deep-outcome
  1. Since ReadOnlyCollection<T> exposes indexer, its naming should be ReadOnlyList<T> to stuck with current approach.
  2. Implementing ICollection<T>, IList<T>, IList is also debatable. Since .NET Core is brand new, one could have been observing more changes to collection designs:
    • Saying that ReadOnlyCollection<T> is implementing these is as well designed as design IReadOnlyList<T> in manner where public indexer public T this[int index] { get; } will have setter part supposed to throwing NotImplementedException.
    • Proper way is to redesign read-only interfaces in a way that they are providing non-altering methods like Contains(T), IndexOf(T) and remove these methods from their alter-also counterparts. So for instance ICollection<T>.Contains(T) should be sited to IReadOnlyCollection<T>. Alike IList<T>.IndexOf<T> should be in IReadOnlyList<T>. Then altering interface should implement read-only interface in natural logic way of inheritance design.

Then there can be ReadOnlyList<T> not implementing many methods that throws exception. 👍

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions