zoukankan      html  css  js  c++  java
  • 序列化 对象 不需要创建文件的方法?

                UserProfile profile = new UserProfile();

                XmlSerializer serializer = new XmlSerializer(typeof(UserProfile));
                MemoryStream ms = new MemoryStream();
                using(TextWriter w = new StreamWriter( ms,System.Text.Encoding.UTF8 ))
                {
                    serializer.Serialize(ms,profile);
                }

                string xml=System.Text.Encoding.UTF8.GetString(ms.ToArray());

       XmlSerializer serializer = new XmlSerializer(typeof(ListItems));
                           XmlDocument doc = new XmlDocument();
                           const string root = @"<?xml version=""1.0""?>";
                           string xmlContent = root + HttpUtility.HtmlDecode(strExtend);
                           doc.LoadXml(xmlContent);
                           System.IO.MemoryStream stream = new System.IO.MemoryStream();
                           doc.Save(stream);
                           stream.Seek(0, SeekOrigin.Begin);
                           XmlSerializerNamespaces xmlns = new XmlSerializerNamespaces();
                           xmlns.Add(String.Empty, String.Empty);
                           ListItems  m_ItemList = serializer.Deserialize(stream) as ListItems;

       XmlSerializer serializer = new XmlSerializer(typeof(List<Option>));
                        string strContent = myRow["Options"].ToString();
                        XmlDocument doc = new XmlDocument();
                        doc.LoadXml(strContent.TrimEnd('?'));
                        System.IO.MemoryStream stream = new System.IO.MemoryStream();
                        doc.Save(stream);
                        stream.Seek(0, SeekOrigin.Begin);

                        List<Option> myList = serializer.Deserialize(stream) as List<Option>;

     

  • 相关阅读:
    安卓模拟器BlueStacks 安装使用教程(图解)
    照相机滤镜使用,优化解码和滤镜导致的预览卡屏现象
    移动语音引擎相关开发笔记
    Linux下查看硬件信息的方法
    linux下彻底卸载mysql 图解教程
    linux下yum安装及配置
    mybatis中的resultMap
    项目管理模式之如何去除SVN标记
    myeclipse中的classpath
    Spring的AOP配置
  • 原文地址:https://www.cnblogs.com/DotNet1010/p/1145471.html
Copyright © 2011-2022 走看看