我正在尝试进行休息api调用,我想要读取运行时已知的对象。例如,简化了代码。
object o = null;
if (True) //condition irrelevant just to indicate selection control
o = new List<Product>();
else
o = new Product();
HttpResponseMessage response = await client.GetAsync(path);
o = await response.Content.ReadAsAsync<o.GetType()>();
o.GetType()不是正确的方法。我能做些什么可以在运行时确定正确的泛型类型吗?
答案 0 :(得分:1)
o = await response.Content.ReadAsAsync(o.GetType())