I have a class with the following two methods
class Foo
{
public async Task Perform(Func<Task> func)
{
await func();
}
public async Task Perform(Func<Task<bool>> func)
{
await func();
}
}
Everything works as expected when I call the methods with funcs
await foo.Perform(async () => { /* */ }); // calls first method
await foo.Perform(async () => true); // calls second method
However, if I try to call the first method (Func<Task>
) with a method delegate I get the following compilation error: "Expected a method with Task ReturnTask() signature"
class Bar
{
public async Task Call()
{
var foo = new Foo();
await foo.Perform(ReturnTask); // compilation error
await foo.Perform(ReturnTaskOfBool); // works
}
private Task ReturnTask()
{
return Task.Completed;
}
private Task<bool> ReturnTaskOfBool()
{
return Task.FromResult(true);
}
}
Any ideas why this is? Is there some way around it, besides making the name of the methods unique?