コード例 #1
0
        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());
        }
コード例 #2
0
        public static T LoadFromXmlFile <T>(string fileName) where T : class
        {
            StreamReader streamReader = new StreamReader(fileName);

            return(GenericXmlSerializer.ReadFromXmlString <T>(streamReader.ReadToEnd()));
        }