Skip to content

Allow type parameters to be declared co/contra variant on classes. #171

@mburbea

Description

@mburbea

Currently type parameters can be declared co/contra variant on either an interface or a delegate. I propose adding support for classes.

The rules would remain the same, any in T cannot appear as any method return type nor on gettable properties. Any out T cannot appear as a parameter or on settable properties. My main motivation for this is really around things like Task<T> where I sometimes want to collect Task<Dog>, Task<Cat>, Task<Fish> into a collection of IEnumerable<Task<Pet>> and whenAlll/whenAny and only inspect their pet based result.

It cannot be legal on structs as the assignment would be a copy operation.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions