Note: I've found another solution to this problem, and have posted an update here
I've subscribed to the Joy Of Code blog for a few weeks now, probably ever since seeing their Validator Module (which I STILL should implement!). In that short amount of time, I'm amazed at the number of times that their posts have directly affected the code that I'm currently working on. Today's post, Using Generics as Parameters, is something that I was looking for about a week or two ago, when implementing some generic serialization/deserialization code.
I was able today to go back and refactor it using generic parameters instead of passing the type...
public static T DeSerialize<T>(string s)
{
T frm = default(T);
try
{
XmlSerializer xs;
StringReader sr = new StringReader(s);
xs = new XmlSerializer(typeof(T));
frm = (T)xs.Deserialize(sr);
sr.Close();
}
catch { }
return frm;
}
Check out The Joy of Code!