HighTechTalks DotNet Forums  

XmlSerializer: Dealing with an evolving class

Dotnet XML microsoft.public.dotnet.xml


Discuss XmlSerializer: Dealing with an evolving class in the Dotnet XML forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Joel Moore
 
Posts: n/a

Default XmlSerializer: Dealing with an evolving class - 06-21-2006 , 04:54 PM






We have an app that currently uses SOAP for a data file format. It works
well enuogh but I would prefer an XML format that's a little friendlier
to the human eye.

I had started looking at converting over to using the XmlSerializer but
quickly ran into a problem. One thing that is nice about the SOAP
formatter's deserialization is that it can easily deal with different
versions of the data file. The class we're serializing includes a
version field and when deserializing we can examine what version file
we're reading and easily deal with missing or changed fields. For
example:

version = info.GetInt32("Version")
...
If version = 1 Then
Me.PropertyA = info.GetInt32("OldPropertyName")
End If

If version = 2 Then
Me.PropertyA = info.GetInt32("PropertyA")
End If

In other words, SOAP allows you to do something with fields or properties
that have been removed from the class (for whatever reason) but are still
contained in the old versions of the data. The above example is
simplistic and the real situations get more complicated than that but
hopefully you can get the idea.

Anyway, with XmlSerializer the above isn't possible. In the newer
versions of the software those old properties will simply be ignored when
deserializing the file since they aren't part of the class anymore. I
could leave them in the class but that starts to turn the class into a
mess and they will continue to be serialized.

So, is there a serialization mechanism in .NET that works the same as
SOAP (i.e. all available elements loaded into a dictionary of some sort)
but allows me complete control over the output formatting to make it
easier to read?

Thanks for any advice,
Joel Moore

Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.