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

  • 相关阅读:
    第四次作业
    软工第三次作业
    第三次作业
    第二次作业
    团队第三次作业:Alpha版本发布
    软件工程团队作业--Alpha版本第二周小结
    软件工程团队作业--Alpha版本第一周小结
    团队第二次作业
    C++多态性总结
    第四次作业:结对编程
  • 原文地址:https://www.cnblogs.com/lyl6796910/p/3803052.html
Copyright © 2011-2022 走看看