zoukankan      html  css  js  c++  java
  • 序列化 和 反序列化 类

    public class Formater
        {
            public static byte[] Serialize(Object _object)
            {
                BinaryFormatter binaryFormatter = new BinaryFormatter();
                MemoryStream ms = new MemoryStream();
              
                binaryFormatter.Serialize(ms, _object);
              
                ms.Position = 0;
              
                byte[] b;
                b = new Byte[ms.Length];
                ms.Read(b, 0, b.Length);
                ms.Close();
                return b;
            }
            public static Object Deserialize(byte[] serializes)
            {
                Object obj = new object();
                if (serializes.Length == 0) return null;
                try
                {
                    BinaryFormatter binaryFormatter = new BinaryFormatter();
                    MemoryStream ms = new MemoryStream();
                    ms.Write(serializes, 0, serializes.Length);
                    ms.Position = 0;

                    obj = binaryFormatter.Deserialize(ms);
                    ms.Close();
                }
                catch
                {
                    obj = null;
                }
                return obj;
            }
        }

  • 相关阅读:
    css3中calc()使用
    垂直居中
    QLineEdit IP地址校验
    UML类图几种关系的总结(网摘)
    如何解压 Mac OS X 下的 PKG 文件(网摘)
    %appdata%目录下配置文件修改
    文件字符串替换
    Qt版权符号显示问题
    Mac OS X 终端命令开启功能
    Qt 无边框拖拽实现
  • 原文地址:https://www.cnblogs.com/zlddtt/p/1544230.html
Copyright © 2011-2022 走看看