• 序列化 对象 不需要创建文件的方法?


                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>;

     

  • 相关阅读:
    Django资源大全
    iPhone企业应用实例分析之一:系统介绍和需求及主要用例
    iPhone SDK开发基础之使用UITabBarController组织和管理UIView
    iPhone企业应用实例分析之四:技术要点分析(1)
    头衔的权威暗示影响力
    什么是云存储技术与云存储服务?
    读书:《SEO实战密码》
    iPhone SDK开发基础之使用UINavigationController组织和管理UIView
    iPhone SDK开发基础之自定义仪表控件
    iPhone企业应用实例分析之三:程序框架分析
  • 原文地址:https://www.cnblogs.com/DotNet1010/p/1145471.html
Copyright © 2020-2023  润新知