473,397 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Serializing 2 instances of the same type, in a single Class?

How do i serialize two instances (of some object) in the
same class? I'm not sure how i would de-serialize a
class that has two or more instances of some object type,
and how the deserialize method would KNOW which
serialized instance to read.

eg.

class Foo
{
objA arraylist()
objB arraylist()
}

public GetObjectData(...)
{
objA.GetObjectInfo(..);
objB.GetObjectInfo(..);
}
how would the DE-SERIALIZED CONSTRUCTOR know which
arraylist to de-serialize?

-PK-
Jul 19 '05 #1
1 2084
When Foo gets serialized a key value pair is created for every field. So
for foo there is two keys "objA" and "objB" with the values being the
serialization of objA and objB respectivly. Then on deserialization the
same key value pairs exist so when it finds the key "objA" it assigns objA
to the deserialization of the value and the same occurs with objB. This
would be accomplished by the following code if you did not want to use the
default serialization method:

class Foo : ISerializable
{
ArrayList objA;
ArrayList objB;

void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.Add("objA", objA);
info.Add("objB", objB);
}

public Foo(SerializationInfo info, StreamingContext context))
{
objA = info.GetValue("objA", typeof(ArrayList);
objB = info.GetValue("objB", typeof(ArrayList);
}
}

If you use the default serialization method by adding the attribute
[Serializable] to Foo I think it does pretty much the same thing.

I am not sure if this answers you question let me know if you have any
further questions.

Thanks,

Ryan Byington [MS]

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
--------------------
Content-Class: urn:content-classes:message
From: "Pure Krome" <su*****@real.com>
Sender: "Pure Krome" <su*****@real.com>
Subject: Serializing 2 instances of the same type, in a single Class?
Date: Sun, 27 Jul 2003 21:48:32 -0700
Lines: 27
Message-ID: <03****************************@phx.gbl>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Thread-Index: AcNUw38gTJw851sbSWGyr7cXG/ytgQ==
Newsgroups: microsoft.public.dotnet.general
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:102545
NNTP-Posting-Host: TK2MSFTNGXA12 10.40.1.164
X-Tomcat-NG: microsoft.public.dotnet.general

How do i serialize two instances (of some object) in the
same class? I'm not sure how i would de-serialize a
class that has two or more instances of some object type,
and how the deserialize method would KNOW which
serialized instance to read.

eg.

class Foo
{
objA arraylist()
objB arraylist()
}

public GetObjectData(...)
{
objA.GetObjectInfo(..);
objB.GetObjectInfo(..);
}
how would the DE-SERIALIZED CONSTRUCTOR know which
arraylist to de-serialize?

-PK-


Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Aleksei Guzev | last post by:
Imagine one writing a class library CL1 for data storage. He defines classes ‘DataItem’ and ‘DataRecord’ so that the latter contains a collection of the former. And he derives class ‘IntItem’ from...
4
by: Wayne Wengert | last post by:
I am still stuck trying to create a Class to use for exporting and importing array data to/from XML. The format of the XML that I want to import/export is shown below as is the Class and the code I...
2
by: Tobias Zimmergren | last post by:
Hi, just wondering what serializing really is, and howto use it? Thanks. Tobias __________________________________________________________________ Tobias ICQ#: 55986339 Current ICQ status: +...
0
by: Kenneth Baltrinic | last post by:
Is the following code correct for serializing a quasi-single class, that is a class that has a descreet (though more than one, so not a true singleton) number of static instances and no dynamically...
0
by: Michael Maercker | last post by:
Hi! I'm about to go nuts over my serializing problem. This is my situation: I have a Data-Class that can have children of the same class which are stored in a hashtable, i.e: X has A as a...
1
by: Pure Krome | last post by:
How do i serialize two instances (of some object) in the same class? I'm not sure how i would de-serialize a class that has two or more instances of some object type, and how the deserialize...
3
by: axr | last post by:
Having trouble with Serilization of objects that contain members which are of type Interface eg public class SomeClass { ISomeInterface1 itf1; ClassType1 ct1; ISomeInterface2 itf2;
0
by: Shaul | last post by:
Hi, My goal is to serialize a collection of type IList<AbstractClass> which contains derived objects instances. My domain object model is a bit complex so I've created a demmi one: public...
5
by: pgrazaitis | last post by:
I cant seem to get my head wrapped around this issue, I have myself so twisted now there maybe no issue! Ok so I designed a class X that has a few members, and for arguments sake one of the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
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...
0
tracyyun
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.