コード例 #1
0
        public static T DeserializeObjectFromXDocument <T>(XDocument value)
        {
            var doc = new XDocument(value);

            using (var reader = doc.CreateReader())
                return((T)XmlSerializerCache.GetXmlSerializer(typeof(T)).Deserialize(reader));
        }
コード例 #2
0
        public static XDocument SerializeObjectToXDocument <T>(T value)
        {
            var doc = new XDocument();

            using (var writer = doc.CreateWriter())
                XmlSerializerCache.GetXmlSerializer(typeof(T)).Serialize(writer, value);

            /* Any XmlCommentAttributes in 'value' are *not* automatically inserted into the
             * XDocument result 'doc' by the call to Serialize().
             *
             * The comments have to be inserted by a separate call to InsertXmlComments(). */

            /* This must be executed after writer has been closed. */
            InsertXmlComments(value, doc.Elements(), 1);

            return(doc);
        }
コード例 #3
0
 public static T DeserializeObjectFromXmlString <T>(String s)
 {
     using (var sr = new StringReader(s))
         return((T)XmlSerializerCache.GetXmlSerializer(typeof(T)).Deserialize(sr));
 }
コード例 #4
0
 public static T DeserializeObjectFromXmlFile <T>(String filename)
 {
     using (var fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read))
         return((T)XmlSerializerCache.GetXmlSerializer(typeof(T)).Deserialize(fs));
 }