473,327 Members | 2,025 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,327 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 2078
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.