I have a JSON deserializer (shown below) which works perfectly fine when I call it with a known type.
public static T Deserialize<T>(this object obj)
{
var javaScriptSerializer = new JavaScriptSerializer();
return (obj != null) ?
javaScriptSerializer.Deserialize<T>(obj.ToString()) :
default(T);
}
So this call will work:
var newExampleTypeX = exampleJsonString.Deserialize<ExampleTypeX>();
However, what I'm trying to do is pass in a type which is set at runtime and use it in place of the "ExampleTypeX". When I do I get the following compilation error:
Cannot resolve symbol 'someType'
So the declaration of someType looks like so (this is a simplified version):
var someType = typeof(ExampleTypeX);
var newExampleTypeX = message.Deserialize<someType>();
Should I be altering my Deserialize extension method somehow, or altering how I pass in the runtime type? If so then how do I achieve that.