Skip to content

Please add function overloads for IReadOnlyCollection #7956

@RioMcBoo

Description

@RioMcBoo

ICollection is very rarely implemented in custom types because, for syntactic sugar, it's sufficient to implement the Add(TValue item) method with any return type.

  1. It's usually very convenient to implement bool Add(TValue item) because its operation is easy to control without having to first use bool Contains(TValue item). Otherwise, you'll encounter exceptions. In any case, this reduces code performance because bool Contains(TValue item) is essentially already implemented in the bool Add(TValue item) method under the hood. You're probably familiar with the slowness of exceptions.

  2. Often, validation methods such as CollectionAssert.AreEqual and similar methods don't change anything in collections anyway. Therefore, choosing ICollection as the argument type isn't a good idea. (I assume this was done to support legacy versions of C#.)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions