Skip to content

Covariant return types with ITask #15

@MgSam

Description

@MgSam

Not really an issue per say, just wanted to suggest that you update your documentation to reflect that this also works really well with covariant return type support that was added in C# 9.0.

Here's a small example if you want one for your tests or docs:

[TestFixture]
public class MyTests
{
    [Test]
    public async Task MyTest()
    {
        var pz = new PettingZoo();
        var an = await pz.GetAnimal().ConfigureAwait(false);
        Assert.AreEqual("Cat", an.Name);
    }
}

public class Zoo
{
    public virtual async ITask<Animal> GetAnimal()
    {
        await Task.Delay(0).ConfigureAwait(false);
        return new Animal();
    }
}

public class PettingZoo : Zoo
{
    public override async ITask<Cat> GetAnimal()
    {
        await Task.Delay(0).ConfigureAwait(false);
        return new Cat();
    }
}

public class Animal
{
    public string Name { get; set; } = "Animal";
}

public class Cat : Animal
{
    public Cat()
    {
        Name = "Cat";
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions