Tech Off Thread

5 posts

Serialization/Deserialization of changed entity

Back to Forum: Tech Off
  • User profile image
    ferguslogic

    I have a question regarding .net Serialization...

    Heres an example to help illustrate my question.

    What happens if I have a custom business object similar to this:

    [serializable]
    public class Customer
    {
           public CustomerName {get{}set{}
    }


    and i build serialization/deserialization code for this entity so that it can be written and read back from an xml file.
    (no problems so far..the world is round)

    Now, I decide I need an extra field in my business entity and so I change it to this...

    [serializable]
    public class Customer
    {
           public CustomerName {get{}set{}
           public CustomerPhone {get{}set{}

    }


    Now..can i still deserialize the xml file that  I created before the object was modified?

    thanks in advance!

  • User profile image
    evildictait​or

    With binary serialization, no. I don't know about XML-based serialization, but I suspect not.

  • User profile image
    stevo_

    You might be able to with the default xml serialization.. but if not, you can implement ISerializable and write your own logic for its serialization and deserialization.

  • User profile image
    JChung2006

    With WCF, you can if you implement IExtensibleDataObject.

  • User profile image
    Yggdrasil

    If I remember correctly, binary serialization in .NET 2.0 added support for [Optional] properties, so if I have a missing member in the serialized form I can ignore it, give it a default value and create the object with default values.

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.