Click here to Skip to main content
15,892,480 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
Questionerror-data reader already open Pin
manjusha s3-Jun-09 2:35
manjusha s3-Jun-09 2:35 
AnswerRe: error-data reader already open Pin
Pete O'Hanlon3-Jun-09 3:02
mvePete O'Hanlon3-Jun-09 3:02 
QuestionRegistry Hive by name? Pin
lee232-Jun-09 22:27
lee232-Jun-09 22:27 
AnswerRe: Registry Hive by name? Pin
Simon P Stevens3-Jun-09 4:27
Simon P Stevens3-Jun-09 4:27 
GeneralRe: Registry Hive by name? Pin
Not Active3-Jun-09 10:14
mentorNot Active3-Jun-09 10:14 
GeneralRe: Registry Hive by name? Pin
Simon P Stevens3-Jun-09 11:11
Simon P Stevens3-Jun-09 11:11 
GeneralRe: Registry Hive by name? Pin
lee233-Jun-09 13:27
lee233-Jun-09 13:27 
QuestionXML Serialization Problem with properties that when set change object status Pin
Sebastian Streiger2-Jun-09 2:32
Sebastian Streiger2-Jun-09 2:32 
Hi fellows,
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
Sebastián Streiger

Imports System.IO
Imports System.Xml
Imports System.Xml.Serialization
Imports System.Reflection

Public Enum estados
unchanged
modified
End Enum
Public Class BaseEntityWithState
Private Shared Function getXmlTypeMapping(ByVal tipo As System.Type) As XmlTypeMapping
Return (New XmlReflectionImporter).ImportTypeMapping(tipo)
End Function
Public Function serialize() As String
Dim writer As New StringWriter
With New XmlSerializer(Me.GetType())
.Serialize(writer, Me)
End With
Return writer.ToString
End Function
Private Shared Function getXmlSerializer(ByVal tipo As System.Type) As XmlSerializer
Return New XmlSerializer(getXmlTypeMapping(tipo))
End Function
Public Function DesSerializar(ByVal tipo As System.Type, ByVal xml As String) As Object
Return New XmlSerializer(tipo).Deserialize(New StringReader(xml))
End Function
Public Function clone() As BaseEntityWithState
Dim aux As BaseEntityWithState = Me.DesSerializar(Me.GetType(), Me.serialize)
Return aux
End Function
Private status As estados = estados.unchanged
Public Property currentStatus() As estados
Get
Return Me.status
End Get
Set(ByVal value As estados)
Me.status = value
End Set
End Property

End Class
Public Class childEntityWithState
Inherits BaseEntityWithState
Private _value As Integer
Public Property value() As Integer
Get
Return Me._value
End Get
Set(ByVal value As Integer)
Me._value = value
Me.currentStatus = estados.modified
End Set
End Property
'Public Property currentStatus2() As estados
' Get
' Return MyBase.currentStatus
' End Get
' Set(ByVal value As estados)
' MyBase.currentStatus = value
' End Set
'End Property
End Class
AnswerRe: XML Serialization Problem with properties that when set change object status [modified] Pin
Moreno Airoldi3-Jun-09 1:35
Moreno Airoldi3-Jun-09 1:35 
GeneralRe: XML Serialization Problem with properties that when set change object status Pin
Sebastian Streiger3-Jun-09 2:23
Sebastian Streiger3-Jun-09 2:23 
GeneralRe: XML Serialization Problem with properties that when set change object status Pin
Moreno Airoldi3-Jun-09 3:03
Moreno Airoldi3-Jun-09 3:03 
GeneralRe: XML Serialization Problem with properties that when set change object status Pin
Sebastian Streiger3-Jun-09 3:22
Sebastian Streiger3-Jun-09 3:22 
GeneralRe: XML Serialization Problem with properties that when set change object status Pin
Moreno Airoldi3-Jun-09 22:36
Moreno Airoldi3-Jun-09 22:36 
GeneralRe: XML Serialization Problem with properties that when set change object status Pin
Sebastian Streiger4-Jun-09 4:40
Sebastian Streiger4-Jun-09 4:40 
GeneralRe: XML Serialization Problem with properties that when set change object status Pin
Moreno Airoldi4-Jun-09 4:47
Moreno Airoldi4-Jun-09 4:47 
QuestionPlaying smoothly small pieces with DirectSound Pin
Andrey U2-Jun-09 0:09
Andrey U2-Jun-09 0:09 
AnswerRe: Playing smoothly small pieces with DirectSound Pin
molesworth2-Jun-09 3:31
molesworth2-Jun-09 3:31 
GeneralRe: Playing smoothly small pieces with DirectSound Pin
Andrey U2-Jun-09 4:18
Andrey U2-Jun-09 4:18 
GeneralRe: Playing smoothly small pieces with DirectSound Pin
molesworth2-Jun-09 6:58
molesworth2-Jun-09 6:58 
AnswerRe: Playing smoothly small pieces with DirectSound Pin
Mark Salsbery2-Jun-09 8:26
Mark Salsbery2-Jun-09 8:26 
GeneralRe: Playing smoothly small pieces with DirectSound Pin
Andrey U2-Jun-09 22:37
Andrey U2-Jun-09 22:37 
GeneralRe: Playing smoothly small pieces with DirectSound Pin
molesworth3-Jun-09 0:58
molesworth3-Jun-09 0:58 
GeneralRe: Playing smoothly small pieces with DirectSound Pin
supercat93-Jun-09 7:07
supercat93-Jun-09 7:07 
GeneralRe: Playing smoothly small pieces with DirectSound Pin
molesworth3-Jun-09 8:47
molesworth3-Jun-09 8:47 
GeneralRe: Playing smoothly small pieces with DirectSound Pin
Mark Salsbery3-Jun-09 9:53
Mark Salsbery3-Jun-09 9:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.