XMLHelper.cs 831 B

1234567891011121314151617181920212223242526272829303132
  1. using Newtonsoft.Json;
  2. using Newtonsoft.Json.Linq;
  3. using System.Numerics;
  4. using System.Xml;
  5. using System.Xml.Linq;
  6. using System.Xml.Serialization;
  7. namespace Infrastructure
  8. {
  9. public static class XmlHelper
  10. {
  11. public static T DeserializeXmlFile<T>(string filePath)
  12. {
  13. try
  14. {
  15. XmlSerializer serializer = new XmlSerializer(typeof(T));
  16. using (FileStream fileStream = new FileStream(filePath, FileMode.Open))
  17. {
  18. return (T)serializer.Deserialize(fileStream);
  19. }
  20. }
  21. catch (Exception ex)
  22. {
  23. throw new Exception($"Error deserializing XML file: {ex.Message}");
  24. //return default(T);
  25. }
  26. return default(T);
  27. }
  28. }
  29. }