码迷,mamicode.com
首页 > Windows程序 > 详细

c# XML序列化

时间:2018-09-28 21:21:14      阅读:322      评论:0      收藏:0      [点我收藏+]

标签:begin   serialize   oid   origin   col   ret   序列化   HERE   lse   

 public static T Deserialize<T, S>(S stream) where S : Stream where T : class, new()
        {
            using (stream)
            {
                XmlSerializer xmlSearializer = new XmlSerializer(typeof(T));
                //    fileStream.Position = 0;
                // fileStream.Seek(0, SeekOrigin.Begin);
                return (T)xmlSearializer.Deserialize(stream);
            }

        }

        public static void Serialize<T, S>(T obj, S stream) where S : Stream where T : class, new()
        {
            using (stream)
            {
                XmlSerializer xmlFormat = new XmlSerializer(typeof(T));
                xmlFormat.Serialize(stream, obj);
            }
        }

 

c# XML序列化

标签:begin   serialize   oid   origin   col   ret   序列化   HERE   lse   

原文地址:https://www.cnblogs.com/yuanzijian-ruiec/p/9720885.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!