如何在文件流中序列化HtmlElement对象? [英] How to serialize HtmlElement object in file stream??

查看:76
本文介绍了如何在文件流中序列化HtmlElement对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在文件流中序列化HtmlElement对象?

How to serialize HtmlElement object in file stream??

推荐答案

使用此代码将任何对象序列化为文件流...在您这种情况下,请替换对象输入HtmlElement

use this code to serialize any object into a file stream ... in your case replace the Object type into HtmlElement

Object obj=new Object();
     XmlSerializer sw = new XmlSerializer(typeof(Object));
     FileStream fs = new FileStream("**Full FilePath**", FileMode.OpenOrCreate);
     sw.Serialize(fs, obj);
     fs.Close();



希望这能帮到您,祝您好运.



hope this helped,good luck.


非常感谢,我会检查出来的.
thanks a lot, i will check it out.


hmmmmm ...是的,XML序列化无法正常工作如果您的类没有无参构造函数:sigh:解决方法之一是为HTMLElement类创建一个包装器类,如下面的代码,然后序列化该包装器类
hmmmmm ... yeah XML serialization is not gonna work for you if the class does not have parameterless constructor :sigh: one way to go around that is to create a wrapper class for the HTMLElement class like the code below and serialize the wrapper class
public class HtmlElementWrapper
       {
           public HtmlElementWrapper()
           { }

           public HtmlElementWrapper(HtmlElement htmlElement)
           {
               this.HtmlElement = htmlElement;
           }

           public HtmlElement HtmlElement
           { get; set; }
       }


或者您也可以使用Binary Serialization(二进制序列化)查看该文章,

使用C#进行对象序列化

祝你好运


or you can use Binary Serialization check out this article for that

Object Serialization using C#

good luck


这篇关于如何在文件流中序列化HtmlElement对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆