I have a method that is defined to receive two parameters. One is a generic type, the other is a function with a generic return type:
public class MyHelperClass<TRequest, TResponse>
{
public TResponse Execute(TRequest request, Func<IDataRecord, TResponse> builder){ ... }
}
Then I have an object that has a method I want to pass in as a delegate
public class MyObject
{
public TResponse BuildMe(IDataRecord rdr){ ... }
}
//call like this
MyHelperClass.Execute(input, myObjectInstance.BuildMe);
but I get an error stating:
“Expected a method with ‘TRequest BuildResponse(IDataRecord)’
why is it expecting a TRequest as a return instead of a TResponse??



Because this:
.. should be:
..otherwise,
TResponsein that class is aTRequest.