Xml Deserializer


/ Published in: C#
Save to your folder(s)

Deserialize an XML object to an T type.


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.