C# method group type inference

Viewed 649

I'm trying to write a generic method that supplies parameters and calls a function, like this:

class MyClass {
    public int Method(float arg) => 0;
}

TResult Call<T1, TResult>(Func<T1, TResult> func) =>
    func(default(T1));

void Main()
{
    var m = new MyClass();
    var r1 = Call<float, int>(m.Method);
    var r2 = Call(m.Method); // CS0411
}

The last line fails to compile with CS0411. Is there any workaround to get type inference to work here?

Use case: using AutoFixture to generate function call parameters.

1 Answers
Related