I have this senario where I need to provide a type for json deserialization, how do I make it dynamic?
Here the code uses an example class name(rd.ds.SDK.re.sa), but in the real code the type will be constructed using data from database.
Type dynamicalyCreatedAtRuntime = Type.GetType("rd.ds.SDK.re.sa");
var response = webRequest.ReadJsonResponseAs<Result<AnalysisResult<dynamicalyCreatedAtRuntime>>();
public static T ReadJsonResponseAs<T>(this HttpWebRequest webRequest)
{
using (System.IO.Stream responseStream = webRequest.GetResponse().GetResponseStream())
{
using (System.IO.StreamReader sr = new System.IO.StreamReader(responseStream))
{
T result = JsonConvert.DeserializeObject<T>(sr.ReadToEnd());
responseStream.Close();
return result;
}
}
}