container icon indicating copy to clipboard operation
container copied to clipboard

Proposal: Implement resolution of IReadOnlyCollection[T] and IReadOnlyList[T]

Open BryantL opened this issue 5 years ago • 1 comments

With the change in resolution behaviour of IEnumerable[T] (switching to deferred resolution of items) the only "built-in" "up front" resolution of collections is via an Array (strictly speaking knowing that IEnumerable is deferred or not is an implementation detail, however it is a detail that some come to rely upon, especially if there is a desire to avoid concrete types... see below).

Using an array is effective however in many scenarios its preferable to use an interface rather than a concrete type.

IReadOnlyCollection[T] and IReadOnlyList[T] were introduced in .Net 4.5.

The proposal is to implement resolution of these interfaces as an alternative to resolving an array. As an implementation detail, the logic for resolving an array would be used and then "cast" to the interface. This ability would not be available on .net 4.0 due to the interfaces not being present. This would not impact these users as the interface is unavailable to them regardless.

As with the array, any existing registrations of the interface would override this "default" resolution mechanism.

Assuming agreement I'm happy to provide a PR for this.

BryantL avatar Feb 02 '20 17:02 BryantL

I think it would be a nice addition. I've added it to the plan.

ENikS avatar Apr 22 '20 00:04 ENikS