Tag: deserialization binaryformatter

从较旧版本的对象反序列化较新版本的对象

假设我有这个课程: [Serializable] public class SomeClass { public SomeClass() {//init} public string SomeString {get;set;} } 应用程序关闭时,此类将获得序列化,并在下次运行时进行反序列化。 然后,我构建它并发布了应用程序,现在该类已更改: [Serializable] public class SomeClass { public SomeClass() {//init} public string SomeString {get;set;} public int SomeInt {get;set;} } 有没有办法在反序列化时将属性设置为默认值,以防在旧的序列化对象中找不到它? 我想到的一种方法是保留类的旧版本,然后检查序列化的版本然后循环旧对象的属性并在新对象中设置它们,但这对我来说没有意义,任何其他有意义的解决方案?

字典在反序列化时为空

我目前正在编写一个双向地图类,我在类的序列化/反序列化方面遇到了一些麻烦(底部的问题)。 这是相关课程的部分内容。 /// /// Represents a dictionary where both keys and values are unique, and the mapping between them is bidirectional. /// /// The type of the keys in the dictionary. /// The type of the values in the dictionary. [Serializable] public class BidirectionalDictionary : IDictionary, IEquatable<BidirectionalDictionary>, ISerializable, IDeserializationCallback { /// /// A dictionary that […]

.NET中的程序集独立序列化

我使用序列化/去序列化技术。 BinaryFormatter类。 每次创建新程序集时,即使类结构相同,BinaryFormatter也不能反序列化二进制数据,但程序集版本不同。 如果类结构保持不变,是否可以反序列化二进制缓冲区而不检查程序集版本?