传递和返回两个不同的泛型类现在我使用Generic1的T
,但可以理解,当我传入sPayload时会出错,因为我不确定如何指定第二个泛型类型。通过方法
public static Generic1 SendReceive<Generic1>(string sUrl, Generic2 sPayload)
{
using(WebClient webclient = new WebClient())
{
webclient.Headers[HttpRequestHeader.ContentType] = "application/json";
string response = webclient.UploadString(sUrl, JsonConvert.SerializeObject(sPayload));
Generic1 parsedResponse = JsonConvert.DeserializeObject<Generic1>(response);
return parsedResponse;
}
}
我想避免使用条件语句,并在硬编码传递的潜在类型。我只是不知道该如何去这样做。