|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Serialize 3 levels of nested collections.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 Hello, Rick,
Your question indicates that your "service" object contains a "chart" object, but you haven't shown the code for clsService, so it's difficult to guess why "chart" might not be being serialized. Perhaps if you can post more code someone will be able to help. Try to reduce the problem to the smallest possible executable example and post the code for that. (Actually, in reducing the problem to the smallest possible executable example the answer often makes itself clear.) Cheers, Randy Rick Luckwell wrote: Show quoteHide quote > 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 >
HTML links
Pls Help me ,about GDI+ fill some image area HTML edit Vb.net how to delete a file when the windows start programmically open a pdf file in vb.net code stopping program Windows Service and StreamWriter Looping through directories ClientScript.RegisterClientScriptBlock in ASP.NET 2.0 WebBrowser: Programmaticaly click an image button |
|||||||||||||||||||||||