Deserialize to newer version [duplicate]

故事扮演 提交于 2019-12-25 02:07:37

问题


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.

The Class was serialized using BinaryFormatter.

Is there a way to do that?

If not, maybe there a way to deserialize and save only the data that appears in both of the versions?


回答1:


If you have the old assembly you can upgrade quite easily by:

  • deserialize to objects with old class type
  • write a mapper mapping old data fields to the fields in the new class
  • serialize the objects of the new class

In the mapper you can convert the old data, add new data etc.



来源:https://stackoverflow.com/questions/15954054/deserialize-to-newer-version

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!