using System.Xml.Serialization; namespace StorageServer.IO; public static class XmlReader { public static void Save(string filePath, T obj) { try { XmlSerializer serializer = new XmlSerializer(typeof(T)); using (FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate)) { serializer.Serialize(fs, obj); } } catch (Exception e) { Console.WriteLine($"Error: {e.Message}"); } } public static T Read(string filePath) { try { XmlSerializer serializer = new XmlSerializer(typeof(T)); using (FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate)) { return (T) serializer.Deserialize(fs); } } catch (Exception e) { Console.WriteLine($"Error: {e.Message}"); return default(T); } } }