我正在尝试做一个休息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()不是正确的方法。我能做些什么可以在运行时为此确定正确的泛型类型?
o = await response.Content.ReadAsAsync(o.GetType())