How can I use serialize and Deserialize to realize Store Function when update code?
-
When I finished serialize and Deserialize,and create a local file . But if i need update code, i create a new variable in SerializationInfo ,for example ,I declare a new variable "A" in code. But when i deserialize exist old local file, the exception warning is "can not find A", so Deserialize failed. How can i do if i want to ignore A when deserialize old files?
-
When I finished serialize and Deserialize,and create a local file . But if i need update code, i create a new variable in SerializationInfo ,for example ,I declare a new variable "A" in code. But when i deserialize exist old local file, the exception warning is "can not find A", so Deserialize failed. How can i do if i want to ignore A when deserialize old files?
-
It depends how your deserialisation is working, but basically you need something in the file to tell you which version the contents were created with.
-
Example of what? I have no idea what your code is doing or how you are managing your data. Just think about what you are trying to do. If you change the definition of a class after it is serialised, then the data will no longer match. So you need some way to use the previous definition to deserialise it. How you achieve this will depend a lot on the structure of your data and the associated classes.
-
Example of what? I have no idea what your code is doing or how you are managing your data. Just think about what you are trying to do. If you change the definition of a class after it is serialised, then the data will no longer match. So you need some way to use the previous definition to deserialise it. How you achieve this will depend a lot on the structure of your data and the associated classes.
Yes, but i have no idea to achieve it...Could u help me? For example, Class A { int a=0; int b=0; } When i finished serialise class A and create a local file "Saved". When i update my Class A Class A { int a=0; int b=0; int c=0; } Then deserialise "Saved", it will throw exception ,how can i do it? I hope when i deserialize "Saved",it will ignore c.
-
Yes, but i have no idea to achieve it...Could u help me? For example, Class A { int a=0; int b=0; } When i finished serialise class A and create a local file "Saved". When i update my Class A Class A { int a=0; int b=0; int c=0; } Then deserialise "Saved", it will throw exception ,how can i do it? I hope when i deserialize "Saved",it will ignore c.
You cannot do it with the new class, because it does not match. You must deserialize into an instance of the old class and then copy the data to the new one. [edit] If the new version of your class is actually based on the original you may be able to do it that way using a cast. Should be easy to test. [/edit]
-
You cannot do it with the new class, because it does not match. You must deserialize into an instance of the old class and then copy the data to the new one. [edit] If the new version of your class is actually based on the original you may be able to do it that way using a cast. Should be easy to test. [/edit]
Oh, actually, my Class is a form , i use serilized to store input data, like textbox or radiobutton data. When my project version update, maybe i will add some textbox or other controls in form class, so i will not deserilize old file, i don't know how to handle it. Please tell me a method to realize save function.
-
Oh, actually, my Class is a form , i use serilized to store input data, like textbox or radiobutton data. When my project version update, maybe i will add some textbox or other controls in form class, so i will not deserilize old file, i don't know how to handle it. Please tell me a method to realize save function.