Skip to content

Covariant return types with ITask #15

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";
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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