反序列化到新版本 [英] Deserialize to newer version
本文介绍了反序列化到新版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个从类序列化的二进制文件. 该课程已更新.
I have a binary file that was serialized from a class. That class has been updated.
现在我需要将旧文件反序列化为新类.
Now I need to deserialize the old file to the new class.
我没有访问旧代码的权限,但是我有访问旧代码的权限.
I don't have access to the old code, but i have access to the old class.
该类使用BinaryFormatter进行了序列化.
The Class was serialized using BinaryFormatter.
有办法吗?
如果没有,也许有一种方法可以反序列化并仅保存两个版本中出现的数据?
If not, maybe there a way to deserialize and save only the data that appears in both of the versions?
推荐答案
如果您使用的是旧程序集,则可以通过以下方式轻松升级:
If you have the old assembly you can upgrade quite easily by:
- 反序列化为具有旧类类型的对象
- 编写一个映射器,将旧数据字段映射到新类中的字段
- 序列化新类的对象
在映射器中,您可以转换旧数据,添加新数据等.
In the mapper you can convert the old data, add new data etc.
这篇关于反序列化到新版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文