0
我想使一个方法接受绑定到Json响应的任何模型,但我无法解决如何动态地将类模型类型插入到通用参数。获取通用参数中使用的类的类型
这是我到目前为止有:
public static async Task<object> DoPost(string url, FormUrlEncodedContent formEnc, object model)
{
using (HttpClient client = new HttpClient())
using (HttpResponseMessage response = await client.PostAsync(url, formEnc))
using (HttpContent content = response.Content)
{
var result = await content.ReadAsStringAsync();
var modelType = model.GetType();
model = JsonConvert.DeserializeObject<modelType>(result);
return model;
}
}
如何获得类型的适当代表为modelType
?