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

     

  • 相关阅读:
    https 证书
    js 压缩
    身份证认证
    在 Visual Studio 2015 中关闭系统级的 Runtime Exceptions
    在 Visual Studio 2015 中关闭 Browser Link
    List<T>.ForEach()的使用
    使用Microsoft.Practices.EnterpriseLibrary.Validation.dll验证类成员
    jQuery.filter()的强大功能
    jQuery Checkbox Selected
    Get SQL String From Query Object In Entity Framework
  • 原文地址:https://www.cnblogs.com/DotNet1010/p/1145471.html
Copyright © 2011-2022 走看看