Posted By

jalalx on 01/18/11


Tagged

xml deserializer


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

cybermax
ovuncgursoy


Xml Deserializer


 / Published in: C#
 

Deserialize an XML object to an T type.

  1. public static T XmlDeserialize<T>(string filename)
  2. {
  3.  
  4. T o = default(T);
  5. try
  6. {
  7. XmlReader reader = XmlReader.Create(filename);
  8. XmlSerializer serializer = new XmlSerializer(typeof(T));
  9. if (serializer.CanDeserialize(reader))
  10. {
  11. o = (T)serializer.Deserialize(reader);
  12. }
  13. reader.Close();
  14. }
  15. catch
  16. {
  17. }
  18. finally
  19. {
  20. }
  21. return o;
  22. }

Report this snippet  

You need to login to post a comment.