c# XML序列化

 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);
            }
        }

 

posted @ 2018-09-28 21:02  紅人  阅读(238)  评论(0编辑  收藏  举报