I'm pulling serialized data from a database along with an object type (where one field contains the object type and one contains an XML string of serialized data).
I've got a generic serializer that has a serialize and deserialize method:
public static class Serializer<T>
{
public static string Serialize(T objectData) { }
public static T Deserialize(string xmlData) { }
}
Given that the object type is specified in the database field, is there any way for me to dynamically set what T is? - This is my line of thought (although this doesn't work):
Type t = Type.GetType(objectTypeName);
t objData = Serializer<t>.Deserialize(objectXmlString);
I was hoping to refactor some code out of a switch statement where T is a set value, but I can't figure out if it can be done, or if so, how I would go about that.
Thanks in advance.