zoukankan      html  css  js  c++  java
  • 序列化

            }

            #endregion

     

            #region SoapFormatter序列化

            /// <summary>

            /// SoapFormatter序列化

            /// 必须类型必须标记为Serializable

            /// </summary>

            /// <param name="obj"></param>

            /// <returns></returns>

            public static string SerializeSoapFormatter(object obj)

            {

                SoapFormatter formatter = new SoapFormatter();

                using (MemoryStream ms = new MemoryStream())

                {

                    formatter.Serialize(ms, obj);

                    byte[] bytes = ms.ToArray();

                    return Encoding.UTF8.GetString(bytes);

                }

            }

            /// <summary>

            /// SoapFormatter反序列化

            /// 必须类型必须标记为Serializable

            /// </summary>

            /// <param name="serializedStr"></param>

            /// <returns></returns>

            public static T DeserializeSoapFormatter<T>(string serializedStr)

            {

                SoapFormatter formatter = new SoapFormatter();

                using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(serializedStr)))

                {

                    return (T)formatter.Deserialize(ms);

                }

            }

            #endregion

  • 相关阅读:
    杭电 1521 排列组合

    杭电 1799 循环多少次?
    杭电1028 Ignatius and the Princess III(整数拆分)
    毕业论文A.1 Matlab环境配置
    Open Graphics Library初步_搭建环境_GLUT
    Open Graphics Library初步_摄影机_GLUT
    C#使用office相关com组件
    插入排序
    二叉树的四种遍历方法(递归、迭代)
  • 原文地址:https://www.cnblogs.com/lyl6796910/p/3803052.html
Copyright © 2011-2022 走看看