c# 二进制序列化

    public static T Deserialize<T, S>(S stream) where S : Stream where T : class, new()
        {
            using (stream)
            {
                BinaryFormatter formatter = new BinaryFormatter();
                return (T)formatter.Deserialize(stream);
            }
        }

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

 

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