I'm having a problem instantiating an anonymous type in my code.
For some reason, TResponse response = default(TResponse);
returns null
, even though TResponse
has a constructor for it.
Am I being dumb?!
Class:
public class MyClass
{
public MyResponse GetResponse(MyRequest request)
{
return Service<MyRequest, MyResponse>.MakeRequest(
request,
delegate() {
return AnotherService.GetRequest(request);
}
);
}
}
Service class
public static class Service<TRequest, TResponse>
where TRequest : IRequest
where TResponse : IResponse
{
public delegate TResponse UseDelegate();
public TResponse MakeRequest(TRequest request, UseDelegate codeBlock)
{
TResponse response = default(TResponse); // <-- Returns nulll
response = codeBlock();
return response;
}
}