Object Property Serialization
-
Hey Guys I'm having problems serializing an class that has an object property, even though the object in the instance of that class is serializable. I've cut the code down to demonstrate:
Option Strict On
Public Class Test
Public Sub New() End Sub Dim m\_text As String Public Property Text() As String Get Return m\_text End Get Set(ByVal Value As String) m\_text = Value End Set End Property
End Class
Public Class TestTag
Public Sub New() End Sub Dim m\_text As String Public Property Text() As String Get Return m\_text End Get Set(ByVal Value As String) m\_text = Value End Set End Property Dim m\_tag As Object Public Property Tag() As Object Get Return m\_tag End Get Set(ByVal Value As Object) m\_tag = Value End Set End Property
End Class
Public Class StartUp
Public Shared Sub Main() Dim ser As New Xml.Serialization.XmlSerializer(GetType(TestTag)) Dim file As New System.IO.StreamWriter("c:\\temp\\test.xml") Dim obj1 As New TestTag Dim obj2 As New Test obj1.Text = "TestTag Object" obj2.Text = "Test Object" obj1.Tag = obj2 ser.Serialize(file, obj1) file.Close() MsgBox("Object Serialized") End Sub
End Class
Really, all i think all i need to do is change the
Tag
property of theTagTest
class to an type that is know to be serialized, i have triedISerializable
but it don't want to know. Failing that, i assume i'll just have to implementISerializable
on theTagTest
class, but it seems a lot of work just for the one property. Any ideas greatly appreciated. Tom -
Hey Guys I'm having problems serializing an class that has an object property, even though the object in the instance of that class is serializable. I've cut the code down to demonstrate:
Option Strict On
Public Class Test
Public Sub New() End Sub Dim m\_text As String Public Property Text() As String Get Return m\_text End Get Set(ByVal Value As String) m\_text = Value End Set End Property
End Class
Public Class TestTag
Public Sub New() End Sub Dim m\_text As String Public Property Text() As String Get Return m\_text End Get Set(ByVal Value As String) m\_text = Value End Set End Property Dim m\_tag As Object Public Property Tag() As Object Get Return m\_tag End Get Set(ByVal Value As Object) m\_tag = Value End Set End Property
End Class
Public Class StartUp
Public Shared Sub Main() Dim ser As New Xml.Serialization.XmlSerializer(GetType(TestTag)) Dim file As New System.IO.StreamWriter("c:\\temp\\test.xml") Dim obj1 As New TestTag Dim obj2 As New Test obj1.Text = "TestTag Object" obj2.Text = "Test Object" obj1.Tag = obj2 ser.Serialize(file, obj1) file.Close() MsgBox("Object Serialized") End Sub
End Class
Really, all i think all i need to do is change the
Tag
property of theTagTest
class to an type that is know to be serialized, i have triedISerializable
but it don't want to know. Failing that, i assume i'll just have to implementISerializable
on theTagTest
class, but it seems a lot of work just for the one property. Any ideas greatly appreciated. TomTry try tagging the classes . _ Public Class Test .... _ Public Class TestTag .... If that doesn't work you may have to declare the Tag property Test. Michael I firmly believe that any man's finest hour, the greatest fulfillment of all that he holds dear, is that moment when he has worked his heart out in a good cause and lies exhausted on the field of battle - victorious. Vince Lombardi (1913-1970)