Properly obsoleting old members in an XML Serializable class in C# VB .NET
Posted
by George
on Stack Overflow
See other posts from Stack Overflow
or by George
Published on 2010-06-11T12:30:54Z
Indexed on
2010/06/11
12:32 UTC
Read the original article
Hit count: 159
Hi! Some time ago I defined a class that was serialized using XML. That class contained a serializable propertyA of integer type. Now I have extended and updated this class, whereby a new propertyB was added, whose type is another class that also has several serializable properties. The new propertyB is now supposed to play the role of propertyA, that is since type of propertyB is another class, one of its members would contain the value that previously propertyA contained, thus making peroptyA obsolete. What I am trying to figure out is how do I make sure that when I desireliaze the OLD version of this class (without propertyB in it), I make sure that the desreializer would take the value of propertyA from the old calss and set it as a value of one of the members of propertyB in a new class?
Private WithEvents _Position As Position = New Position(Alignment.MiddleMiddle, 0, True, 0, True)
Public Property Position() As Position 'NEW composite property that holds the value of the obsolted property, i.e. Alignment
Get
Return _Position
End Get
Set(ByVal value As Position)
_Position = value
End Set
End Property
Private _Alignment As Alignment = Alignment.MiddleMiddle
<Xml.Serialization.XmlIgnore(), Obsolete("Use Position property instead.")> _
Public Property Alignment() As Alignment'The old, obsoleted property that I guess must be left for compliance with deserializing the old version of this class
Get
Return _Alignment
End Get
Set(ByVal value As Alignment)
_Alignment = value
End Set
End Property
Can you help me, please?
© Stack Overflow or respective owner