Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make IImmutableList covariant like IReadOnlyList, IEnumerable etc. #16011

Closed
ghost opened this issue Jan 4, 2016 · 5 comments
Closed

Make IImmutableList covariant like IReadOnlyList, IEnumerable etc. #16011

ghost opened this issue Jan 4, 2016 · 5 comments
Milestone

Comments

@ghost
Copy link

ghost commented Jan 4, 2016

I need System.Collections.Immutable interfaces such as IImmutableList to be covariant just like IReadOnlyList, IEnumerable in order to be able to write stuff like this:

public interface IResources<out T> where T : IDomainEntity
{
        IImmutableList<T> ShouldWorkButCompilerGivesErrorDueToIImmutableListNotCovariant { get; }
        IReadOnlyList<T> Works { get; }
}
@vcsjones
Copy link
Member

vcsjones commented Jan 4, 2016

I don't think it can reasonably be made covariant since the interface has contravariant methods
like Add<T>

@ghost
Copy link

ghost commented Jan 4, 2016

Maybe it can be done if the covariant methods are moved to a new interface like IImmutableListBase that IImmutableList inherits from ?

@CodesInChaos
Copy link

@bluemmc Almost all covariant methods are already on IReadOnlyList<T>. So it sounds like you want is some kind of marker that tells you that this collection is immutable without adding any functionality on top of IReadOnlyList<T>.

@vcsjones
Copy link
Member

vcsjones commented Jan 4, 2016

IImmutableList<T> already implements the IReadOnlyList<T> interface, which is pretty much the interface you're asking for.

@ghost
Copy link

ghost commented Jan 4, 2016

Thanks for all the feedback. You are both right. I will have to do with IReadOnlyList when I need it in covariant form (as I do in my example).

@ghost ghost closed this as completed Jan 4, 2016
@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 1.0.0-rtm milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Jan 3, 2021
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants