I have a question regarding generic methods with two generic arguments. Imagine this:
public class A
{
public string PropertyA {get;set;}
}
---------------------------------------------------------------------------
private string GetProperty<T, P>(Expression<Func<T, P>> expressionProperty)
where T : class
{
return ((MemberExpression)expressionProperty.Body).Member.Name;
}
---------------------------------------------------------------------------
void Main()
{
GetProperty<A>(x => x.PropertyA).Dump();
}
This won't compile:
CS0305 Using the generic method 'UserQuery.GetProperty(Expression>)' requires 2 type arguments
So I have to call the method like this:
void Main()
{
GetProperty<A,string>(x => x.PropertyA).Dump();
}
Why can't the compiler infer the PropertyA
type?