如何对一个类的静态成员进行二进制序列化? [英] How to binary serialize static members of a class?
本文介绍了如何对一个类的静态成员进行二进制序列化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想对一个类进行二进制序列化,该类只包含我在代码中全局使用的静态项(变量和不同类型的对象).
当我想对其进行序列化时,出现错误''EmailAccount"是一种类型,不能用作表达式":
binformatter.Serialize(filstream,EmailAccount);
我什至尝试从类中创建一个对象并对其进行序列化.但这似乎只保存实例变量,而不保存静态变量.
有没有办法序列化它们?
I want to binary serialize a class, which has only static items (variables & objects of different types) which I use globally in my code.
When I want to serialize it, I get the error "''EmailAccount'' is a type and cannot be used as an expression" :
binformatter.Serialize(filstream, EmailAccount);
I even tried to create an object from the class and serialize it. But it seems to only save the instance variables and not the static ones.
Is there a way to serialize them?
推荐答案
这 [^ ]有一个答案,即实现ISerializable
来手动滚动序列化程序.
尽管作为该线程的第一个答复说这是个坏主意".
This[^] has an answer, namely, implementISerializable
to hand-roll a serializer.
Although as the first reply in that thread states "It is a bad idea".
这篇关于如何对一个类的静态成员进行二进制序列化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文