Q: Why can the generic arguments to Inferred not be inferred?
When looking at the example below the type T
can be inferred as Instance
and we can see that we need that method with no arguments which is also supplied. That method returns an TOut
which must be an int
since we cannot have overloads on return types.
public class Instance
{
public int Convert()
{
return 42;
}
}
public static class Example
{
public static void Inferred<T, TOut>(T source, Expression<Func<T, Func<TOut>>> expression)
{
}
public static void Usage()
{
var instance = new Instance();
Inferred(instance, x => x.Convert);
}
}