|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
XML Serialization with of a sub-class of DataTable.I have a very weird problem regarding the serialization of a class that I wrote (named DummyClass in my exemple). My class inherits from DataTable. Then I just try a dummy XMLSerialization and then Deserialize it into a new object. The problem is that everything is fine for the DataTable containt, but nothing of my custom properties added to the DummyClass are serialized properly ! I don't understand why the serialization process works perfectly, but when deserializing, it just skips the custom properties and just take care of the data table content ? why ? Thanks in advanced ! Here is my code : ============================================== <Serializable()> _ Public Class DummyClass Inherits DataTable Private _Name As String Private _Description As String Private _Something As String Public Shared Sub Main() Dim fileToUse As String = "C:\foo.xml" ' Write the instance to the file Dim dummyInstance As New DummyClass() dummyInstance.TableName = "SomeName" dummyInstance.Name = "TheName" dummyInstance.Description = "TheDescription" dummyInstance.Something = "Something He" Dim serializer As New Xml.Serialization.XmlSerializer(GetType(DummyClass)) Dim stream As New IO.StreamWriter(fileToUse) serializer.Serialize(stream, dummyInstance) stream.Close() Dim stream2 As New IO.StreamReader(fileToUse) Dim dummyInstance2 As DummyClass = DirectCast(serializer.Deserialize(stream2), DummyClass) stream2.Close() MsgBox(dummyInstance2.Something & " == " & dummyInstance.Something & " ?") End Sub Public Property Name() As String Get Return _Name End Get Set(ByVal Value As String) _Name = Value End Set End Property Public Property Description() As String Get Return _Description End Get Set(ByVal Value As String) _Description = Value End Set End Property Public Property Something() As String Get Return _Something End Get Set(ByVal Value As String) _Something = Value End Set End Property End Class =============================================== |
|||||||||||||||||||||||