M
Monty
I've created an object (called cMyBindingList) that inherits from
BindingList. I can serialize it and it's child items with no problem.
However, I've also created a public variable in cMyBindingList that I set
when I first create it. This variable, even though it is public, does not
serialize to the XML. What is the reason for this? Is it possible to do it?
TIA for any light you can shed. Here's the sample code (from a form with a
single button on it):
Imports System.ComponentModel
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim oList1 As New cMyBindingList(15) '<-- note that iType is
specified
For i As Integer = 1 To 5 'Load up list
Dim oItem As New cMyItem
oItem.Value1 = i.ToString
oItem.Value2 = i.ToString
oList1.Add(oItem)
Next
Dim oSerializer As New
Xml.Serialization.XmlSerializer(GetType(cMyBindingList))
Dim myWriter As System.IO.StreamWriter = New
System.IO.StreamWriter("C:\MyTest.xml")
oSerializer.Serialize(myWriter, oList1)
End Sub
End Class
<Serializable()> <System.Runtime.InteropServices.ComVisible(False)> _
Public Class cMyBindingList
Inherits BindingList(Of cMyItem)
Public miMyType As Integer '<-- THIS DOES NOT SERIALIZE!
Public Sub New() 'this parameterless constructor required for
deserialization
End Sub
Public Sub New(ByVal iType As Integer)
miMyType = iType
End Sub
End Class
<Serializable()> <System.Runtime.InteropServices.ComVisible(False)> _
Public Class cMyItem
Private msValue1 As String
Private msValue2 As String
Public Property Value1() As String
Get
Return msValue2
End Get
Set(ByVal value As String)
msValue2 = value
End Set
End Property
Public Property Value2() As String
Get
Return msValue1
End Get
Set(ByVal value As String)
msValue1 = value
End Set
End Property
End Class
BindingList. I can serialize it and it's child items with no problem.
However, I've also created a public variable in cMyBindingList that I set
when I first create it. This variable, even though it is public, does not
serialize to the XML. What is the reason for this? Is it possible to do it?
TIA for any light you can shed. Here's the sample code (from a form with a
single button on it):
Imports System.ComponentModel
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim oList1 As New cMyBindingList(15) '<-- note that iType is
specified
For i As Integer = 1 To 5 'Load up list
Dim oItem As New cMyItem
oItem.Value1 = i.ToString
oItem.Value2 = i.ToString
oList1.Add(oItem)
Next
Dim oSerializer As New
Xml.Serialization.XmlSerializer(GetType(cMyBindingList))
Dim myWriter As System.IO.StreamWriter = New
System.IO.StreamWriter("C:\MyTest.xml")
oSerializer.Serialize(myWriter, oList1)
End Sub
End Class
<Serializable()> <System.Runtime.InteropServices.ComVisible(False)> _
Public Class cMyBindingList
Inherits BindingList(Of cMyItem)
Public miMyType As Integer '<-- THIS DOES NOT SERIALIZE!
Public Sub New() 'this parameterless constructor required for
deserialization
End Sub
Public Sub New(ByVal iType As Integer)
miMyType = iType
End Sub
End Class
<Serializable()> <System.Runtime.InteropServices.ComVisible(False)> _
Public Class cMyItem
Private msValue1 As String
Private msValue2 As String
Public Property Value1() As String
Get
Return msValue2
End Get
Set(ByVal value As String)
msValue2 = value
End Set
End Property
Public Property Value2() As String
Get
Return msValue1
End Get
Set(ByVal value As String)
msValue1 = value
End Set
End Property
End Class