I'm getting married! - More Details

Great Blog - The Joy Of Code

Wednesday, May 03, 2006 10:46 AM

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!

Comments

Josh
Thanks Dusty!

I'm glad you're enjoying the blog and I'm delighted that you've actually found the stuff we've posted of some use.

I liked your example above so much I updated the post to contain a link.

Thanks again.

Josh


Post a comment

   
 
  
  

    

All content © Dusty Davidson