I have the following class:
public class MyClass<T> where T : class
{
public void Method1<TResult>(T obj, Expression<Func<T, TResult>> expression)
{
//Do some work here...
}
public void Method2<TResult>(T obj, Expression<Func<T, TResult>> expression1, Expression<Func<T, TResult>> expression2)
{
//Do some work here...
}
}
I can call Method1 like this:
MyClass<SomeOtherClass> myObject = new MyClass<SomeOtherClass>();
myObject.Method1(someObject, x => x.SomeProperty);
But when I try to call Method2:
MyClass<SomeOtherClass> myObject = new MyClass<SomeOtherClass>();
myObject.Method2(someObject, x => x.SomeProperty, x => x.SomeOtherProperty);
I get the following compile-time error:
Error 1 The type arguments for method 'MyClass.Method2<SomeOtherClass>.Method2<TResult>(SomeOtherClass obj, System.Linq.Expressions.Expression<System.Func<SomeOtherClass,TResult>>, System.Linq.Expressions.Expression<System.Func<SomeOtherClass,TResult>>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
How can I make an method that accept two lambdas and call it like I intended?