I´m using the class "BaseEntityWithState" as the base class for lot of aur bussines classes.
Basically it has lots of methods to trak object state (stripped off so only relevanto ones to the problem are shown).
When a child class has one of its porperties modified it changes the state to "modified".
I need to clone the entity and I´m doing that serializing and deserializing the instance.
Supouse I need to clone a child entity wich currentStatus is "unchanges". During the deserialization part of the cloning method, the members of the base class are assigned it´s values properly. Then whe the "Value" property of the child class is set, it changes the currentStatus property of the base class. So the original instance has currentStatus "unchanged" and the cloned one has "modified".
What I need is to be able to avoid that.
I tried setting the Order property of XMLElement atributte to change the serialization order, but the serializer complains that I should specify order for all member of the base an child class. This would be to hard to mantain. Remember there are lots of child classes, each one with several members.
So, the only solution that is working is declaring in the child class, after all other declarations a "currentStatus2" property (commented in the code).
That way this is the last property to get serialized and also the las to get deserialized, propperly setting the currentStatus atributte to the original value.
For this solution to work requires me to add the ficticious property to EVERY child class. Not too much work, but I´m worried that this is not a good solution, cause it requiere other programmers (less techies than me) not to forget to add that property.
I´d like to provide a better solution to this problem.
Thanks in advance
Public Enum estados
Public Class BaseEntityWithState
Private Shared Function getXmlTypeMapping(ByVal tipo As System.Type) As XmlTypeMapping
Return (New XmlReflectionImporter).ImportTypeMapping(tipo)
Public Function serialize() As String
Dim writer As New StringWriter
With New XmlSerializer(Me.GetType())
Private Shared Function getXmlSerializer(ByVal tipo As System.Type) As XmlSerializer
Return New XmlSerializer(getXmlTypeMapping(tipo))
Public Function DesSerializar(ByVal tipo As System.Type, ByVal xml As String) As Object
Return New XmlSerializer(tipo).Deserialize(New StringReader(xml))
Public Function clone() As BaseEntityWithState
Dim aux As BaseEntityWithState = Me.DesSerializar(Me.GetType(), Me.serialize)
Private status As estados = estados.unchanged
Public Property currentStatus() As estados
Set(ByVal value As estados)
Me.status = value
Public Class childEntityWithState
Private _value As Integer
Public Property value() As Integer
Set(ByVal value As Integer)
Me._value = value
Me.currentStatus = estados.modified
'Public Property currentStatus2() As estados
' Return MyBase.currentStatus
' End Get
' Set(ByVal value As estados)
' MyBase.currentStatus = value
' End Set