假如我有這個類:從舊版本的對象的反序列化對象的新版本
[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;}
}
有沒有一種方法來設置屬性其默認值的情況下,反序列化它不是在舊序列中發現目的?
我想過的一種方式是保留舊版本的類,然後檢查已序列化的版本,然後循環舊對象的屬性並將它們設置在新對象中,但這對我來說是無意義的,任何其他有意義的解決方案?
什麼串行器?有些接口/屬性可用於修改對象[de]序列化的方式,但取決於哪個庫。 –
@BradChristie我使用'BinaryFormatter' – FPGA
看一看使用自定義[膠粘劑](http://msdn.microsoft.com/en-us/library/system.runtime.serialization.formatters.binary.binaryformatter.binder (v = vs.110)的.aspx) –