public static string WriteToXmlString(object obj) { XPathNavigator xPathNavigator = GenericXmlSerializer.GetXPathNavigator(obj); XmlWriterSettings xmlWriterSettings = new XmlWriterSettings(); xmlWriterSettings.Indent = true; MemoryStream memoryStream = new MemoryStream(); using (XmlWriter xmlWriter = XmlWriter.Create(memoryStream, xmlWriterSettings)) { xPathNavigator.WriteSubtree(xmlWriter); xmlWriter.Close(); } StreamReader streamReader = new StreamReader(memoryStream); return(streamReader.ReadToEnd()); }
public static T LoadFromXmlFile <T>(string fileName) where T : class { StreamReader streamReader = new StreamReader(fileName); return(GenericXmlSerializer.ReadFromXmlString <T>(streamReader.ReadToEnd())); }