R
Rick Luckwell
I have 3 collections(reports, services, charts) of objects(report,
service, chart) that are nested with each other. When I serialize the
object the output only contains reports and services but not the
charts. Am I missing something? can you serialize to this depth without
extra code? or do I need to call the serialize method of the child
objects?
clsReports.SerializeObject("c:\report.xml", m_AllReports)
'"m_AllReports" contains the collections of object instances I am
trying to serialize
Each collection class is based on the following
<Serializable()> Public Class clsReports
Inherits System.Collections.CollectionBase
Default Public Property Item(ByVal index As Integer) As clsReport
Get
Return CType(Me.List(index), clsReport)
End Get
Set(ByVal value As clsReport)
Me.List(index) = value
End Set
End Property
Public Sub Add(ByVal value As clsReport)
Me.List.Add(value)
End Sub
Public Shared Sub SerializeObject(ByVal filename As String, ByVal
Report As clsReports)
Dim s As New XmlSerializer(GetType(clsReports))
Dim writer As TextWriter = New StreamWriter(filename)
s.Serialize(writer, Report)
writer.Close()
End Sub
Public Shared Function DeserializeObject(ByVal filename As String)
As clsReports
Dim fs As New IO.FileStream(filename, FileMode.Open)
Dim w As New
Xml.Serialization.XmlSerializer(GetType(clsReports))
Dim g As clsReports = CType(w.Deserialize(fs), clsReports)
fs.Close()
Return g
End Function
End Class
And each object is based on the following
<Serializable()> Public Class clsReport
Private m_ReportName As String = ""
Private m_ServList As New clsServices
Public Property Name() As String
Get
Return Me.m_ReportName
End Get
Set(ByVal value As String)
Me.m_ReportName = value
End Set
End Property
Public ReadOnly Property ServiceList() As clsServices
Get
Return Me.m_ServList
End Get
End Property
Public Sub AddService(ByVal NewSvc As clsService)
Me.m_ServList.Add(NewSvc)
End Sub
End Class
service, chart) that are nested with each other. When I serialize the
object the output only contains reports and services but not the
charts. Am I missing something? can you serialize to this depth without
extra code? or do I need to call the serialize method of the child
objects?
clsReports.SerializeObject("c:\report.xml", m_AllReports)
'"m_AllReports" contains the collections of object instances I am
trying to serialize
Each collection class is based on the following
<Serializable()> Public Class clsReports
Inherits System.Collections.CollectionBase
Default Public Property Item(ByVal index As Integer) As clsReport
Get
Return CType(Me.List(index), clsReport)
End Get
Set(ByVal value As clsReport)
Me.List(index) = value
End Set
End Property
Public Sub Add(ByVal value As clsReport)
Me.List.Add(value)
End Sub
Public Shared Sub SerializeObject(ByVal filename As String, ByVal
Report As clsReports)
Dim s As New XmlSerializer(GetType(clsReports))
Dim writer As TextWriter = New StreamWriter(filename)
s.Serialize(writer, Report)
writer.Close()
End Sub
Public Shared Function DeserializeObject(ByVal filename As String)
As clsReports
Dim fs As New IO.FileStream(filename, FileMode.Open)
Dim w As New
Xml.Serialization.XmlSerializer(GetType(clsReports))
Dim g As clsReports = CType(w.Deserialize(fs), clsReports)
fs.Close()
Return g
End Function
End Class
And each object is based on the following
<Serializable()> Public Class clsReport
Private m_ReportName As String = ""
Private m_ServList As New clsServices
Public Property Name() As String
Get
Return Me.m_ReportName
End Get
Set(ByVal value As String)
Me.m_ReportName = value
End Set
End Property
Public ReadOnly Property ServiceList() As clsServices
Get
Return Me.m_ServList
End Get
End Property
Public Sub AddService(ByVal NewSvc As clsService)
Me.m_ServList.Add(NewSvc)
End Sub
End Class