I have 3 collections(rep orts, 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.Seri alizeObject("c: \report.xml", m_AllReports)
'"m_AllRepor ts" 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.Collecti ons.CollectionB ase
Default Public Property Item(ByVal index As Integer) As clsReport
Get
Return CType(Me.List(i ndex), 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(val ue)
End Sub
Public Shared Sub SerializeObject (ByVal filename As String, ByVal
Report As clsReports)
Dim s As New XmlSerializer(G etType(clsRepor ts))
Dim writer As TextWriter = New StreamWriter(fi lename)
s.Serialize(wri ter, Report)
writer.Close()
End Sub
Public Shared Function DeserializeObje ct(ByVal filename As String)
As clsReports
Dim fs As New IO.FileStream(f ilename, FileMode.Open)
Dim w As New
Xml.Serializati on.XmlSerialize r(GetType(clsRe ports))
Dim g As clsReports = CType(w.Deseria lize(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(ByVa l NewSvc As clsService)
Me.m_ServList.A dd(NewSvc)
End Sub
End Class 1 2252
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:
I have 3 collections(rep orts, 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.Seri alizeObject("c: \report.xml", m_AllReports)
'"m_AllRepor ts" 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.Collecti ons.CollectionB ase
Default Public Property Item(ByVal index As Integer) As clsReport
Get
Return CType(Me.List(i ndex), 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(val ue)
End Sub
Public Shared Sub SerializeObject (ByVal filename As String, ByVal
Report As clsReports)
Dim s As New XmlSerializer(G etType(clsRepor ts))
Dim writer As TextWriter = New StreamWriter(fi lename)
s.Serialize(wri ter, Report)
writer.Close()
End Sub
Public Shared Function DeserializeObje ct(ByVal filename As String)
As clsReports
Dim fs As New IO.FileStream(f ilename, FileMode.Open)
Dim w As New
Xml.Serializati on.XmlSerialize r(GetType(clsRe ports))
Dim g As clsReports = CType(w.Deseria lize(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(ByVa l NewSvc As clsService)
Me.m_ServList.A dd(NewSvc)
End Sub
End Class This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: MAY |
last post by:
Hi,
I have a problem about serialize the form controls. I wrote a test program
to test serialize a from but fail (->An unhandled exception of type
'System.Runtime.Serialization.SerializationException' occurred in
mscorlib.dll) . Thx in advance. Here is the part of the code:
Regards
MAY
|
by: Eirik Eldorsen |
last post by:
Im trying to make a nested repeater with 3 levels. I've successfully created
a nested repeater with 2 levels, but when adding the 3rd level I get an
InvalidCastException. What am I doing wrong?
Here is my code:
<asp:Repeater id="level1Repeater" runat="server">
<itemtemplate>
|
by: Ben Amada |
last post by:
I've created a class that I need to store in ViewState. However when I try
to store it in ViewState, I get the following error:
"The type 'solution.pe2' must be marked as Serializable or have a
TypeConverter other than ReferenceConverter to be put in viewstate."
I've included the <Serializable()> attribute, but I'm still getting the same
error.
The class is below ... as you can see it contains a Collection, two
|
by: Atley |
last post by:
I am trying to set up a nested collection so I can run statements like this:
me.lblquestions.text = mysteps.item(1).questions(1).Asked
Any ideas on how to do this? I have created a Class(Steps) with a nested
Class(Questions) inside of it and a Collection of that Class(Steps) and it
works fine, but the Nested Collection(Questions) is escaping me.
Help!
|
by: davebaranas |
last post by:
I am able to serialize this but I get a null exception when I try to
deserialize it back
Even if I don't make any child classes it throws "Object reference not
set to an instance of an object."
I must be missing something here
Private Sub cmdLoad_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles cmdLoad.Click
| |
by: teddysnips |
last post by:
I would like to serialize a class to XML. The format of the XML is
fixed (see below). It only needs to be serialized - it is read by
another application.
I know I can do it manually using XMLTextWriter - e.g.
Dim xwriter = New
XmlTextWriter("C:\Projects\Formflo\WindowsService\NDde\test.xml",
System.Text.Encoding.UTF8)
xwriter.Formatting = Formatting.Indented
|
by: =?Utf-8?B?Qnlyb24=?= |
last post by:
When I try to serialize an instance of the LocationCell below (note Building
field) I get an error in the reflection attempt. If I remove the _Building
field it serializes fine. I tried renaming Building._Name to Building._BName
in case the duplicate name was the issue, but that didn't help.
Is there a native way to serialize nested objects, or will I have to write
my own?
public class LocationCell
|
by: Michi Henning |
last post by:
I can pass a generic collection as ICollection<Tjust fine:
static void flatCollection(ICollection<intc) {}
// ...
List<intl = new List<int>();
flatCollection(l); // Works fine
Now I want to pass nested collections generically:
|
by: =?Utf-8?B?U2hhd24=?= |
last post by:
Hi;
I would like to be able to use the XMLSerializer to serialize and
deserialize a dictionary. is that possible? i know that you can serialize an
object that implements the ICollection interface. does the fact that
Dictionary inherits from ICollection<cause a problem?
Currently i am using a class that inherits from ICollection and it has a
Dictionary as it's container. but when it gets to creating the serialized
object it blows up. here...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |