I am not sure if this can be done but I am wondering if it is possible to specify the 'T' type of a generic at run time. I have an object that has been serialized and stored in the database. The type of the object has also been stored. So when the object is retrieved I have the serialized object stored in a string variable as it's type also stored in a string variable. What I want to be able to do is something like this:
var serializer = new AbcSerializer();
var typeString = "Abc.Group.Common.Domain.DomainObject, Abc.Group.Common.Domain";
var serializedObject = "some serialized data here...";
var retObj = serializer.Deserialize<Type.GetType(typeString)>(serializedObject);
Does someone know if this is possible?
Other questions that are similar to this one talk about using MakeGenericType like this:
Type constructed = d1.MakeGenericType(typeArgs);
And then doing:
object o = Activator.CreateInstance(constructed);
to create an instance of that object. That is not what I am trying to do. I want to create an instance of my object from data that has been serialized.