The java version: I have the generic function as follows:
public <T, K> JsonEnvelop<T, K> readResponse(Class<T> t, Class<K> k)
And one class that implements InvocationHandler, in the invoke function, it will call the generic function just as follows:
JsonEnvelop<ResHeader, ?> response = conn.readResponse(ResHeader.class, method.getReturnType());
Now I want a C# version: Then I translate the generic function as below:
public JsonEnvelop<T, K> readResponse<T,K>()
And I want to call the function in the invoke body of a class that implements RealProxy, how can I achieve the same result as java version? The first generic type can be ResHeader, but the second one should be judged from methodCall, so how can I pass the parameter K?
public override IMessage Invoke(IMessage msg)
{
var methodCall = msg as IMethodCallMessage;
var response = conn.readResponse<ResHeader, Typge.Get(methodCall.TypeName)>();
return new ReturnMessage(response.getBody(), null, 0, methodCall.LogicalCallContext, methodCall);
}
Another question is that is there any better way to translate the java code to C#?
Thanks very much!
Thanks Aron, the detail problem is:
I have different services, and for every service, it would provide several functions. Each function would send a request and get a response. The request and response would differ across functions and services. The design is to use the RealProxy to send the request and get the response. Here the "public JsonEnvelop readResponse(Class t, Class k)" is to get the response, and for different service and function, the T is the same as ResHeader, but the K is quite different and it rely on the parameters.
GetRealTimeQueryDataRequest request = new GetRealTimeQueryDataRequest();
GetRealTimeQueryDataResponse response=reportService.getRealTimeQueryData(request);
Take the above as example, it will call the invoke function in the realproxy implement class and the K should be the return type GetRealTimeQueryDataResponse