I am currently working on a general request / response abstraction to send arbitrary class requests to a component when I receive a given response class based on the request.
I have two base classes:
abstract class RequestClass<T> where T : ResponseClass { } abstract class ResponseClass { }
Thus, the request class defines its own response class. To demonstrate the situation, I have the following class examples:
class DoSomethingRequest : RequestClass<DoSomethingResponse> { } class DoSomethingResponse : ResponseClass { }
Now for processing the request, I have the following method:
TResult SendRequest<T, TResult>( T Request ) where T : RequestClass<TResult> where TResult : ResponseClass { }
So far so good; however, while I expect the following to work, the compiler will not be able to output type parameters for the following request:
DoSomethingResponse Response = SendRequest( new DoSomethingRequest() );
Why is this not working? The compiler must have all the necessary information to conclude that "DoSomethingRequest is RequestClass of DoSomethingResponse" and compiles without problems. Is there any other way to get my script to work?
Help is appreciated. Thanks in advance and best regards! -Simon
source share