473,396 Members | 1,927 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,396 software developers and data experts.

Heirarchical serialization

I haven't used Serialization support in .NET before and I have a few
questions about it.

let's assume the following:

class A : ISerializable
{
....
}

class B : A, ISerializable
{
private C cField;
....
}
class C: ISerializable
{
....
}
First of all, yeah, I'm missing the Serializable attributes here, and a lot
of other stuff, but this should be sufficient for my question..

In class B, how do I define GetObjectData()? I need to define it as new or
override? If it's "new" then from B.GetObjectData() do I simply call
base.GetObjectData() to deserialize the base class A? Does that work in a
"new" method?

What about the class C which is contained within B? In the
B(SerializationInfo, StreamingContext) constructor, do I simply do a cField
= new C(serInfo, context)? In B.GetObjectData() do I just call
cField.GetObjectData(serInfo, context)

Just not really sure how this all goes together. The above seems to make
sense to me except for whether or not B.GetObjectData should be new or
override. Of course, I could be completely off on all of it.

The other question is in regards to classes that aren't serializable. For
example, if I have a member that is a Font class, and I want to serialize
it, do I just take all of the pertinent data from the font object and
serialize those pieces that I need to re-create the font in the serializable
constructor?

Thanks

Pete

Nov 15 '05 #1
1 1228

"Pete Davis" <pd******@hotmail.com> wrote in message
news:a1******************************@news.meganet news.com...
I haven't used Serialization support in .NET before and I have a few
questions about it.

let's assume the following:

class A : ISerializable
{
...
}

class B : A, ISerializable
{
private C cField;
...
}
class C: ISerializable
{
...
}

In class B, how do I define GetObjectData()? I need to define it as new or
override? If it's "new" then from B.GetObjectData() do I simply call
base.GetObjectData() to deserialize the base class A? Does that work in a
"new" method?
A should be virtual and B and other derived types should be override. Be
sure to call the base method after serializing members.

public override void GetObjectData(
SerializationInfo info,
StreamingContext context )
{
info.AddValue("cField", cField, typeof(C));

base.GetObjectData(info,context);
}

What about the class C which is contained within B? In the
B(SerializationInfo, StreamingContext) constructor, do I simply do a cField = new C(serInfo, context)? In B.GetObjectData() do I just call
cField.GetObjectData(serInfo, context)
By calling it in B.GetObjectData, as in the example above, the serializer
will call C.GetObjectData for you.
The other question is in regards to classes that aren't serializable. For
example, if I have a member that is a Font class, and I want to serialize
it, do I just take all of the pertinent data from the font object and
serialize those pieces that I need to re-create the font in the serializable constructor?


You have the right idea.

Joe
--
http://www.csharp-station.com
Nov 15 '05 #2

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

Similar topics

1
by: Richard Rice | last post by:
This may be a basic question, but defining anything other than a cursor is preffered. I have, as an example, 2 tables. One with customer data (addresses, phones, etc), the other is a listing of...
8
by: Manu Ashok | last post by:
pls anybody help me with this. i need to make a query where i have to display all names of a category heirarchically. C1-->C2-->C3-->C4 where C1 is the top level category it shud b...
1
by: Dr Ann Huxtable | last post by:
Hello, I am trying to design an abstract data type (lets call it an HTable) which mimics a heirarchical rcordset (ala ADO 2.0). I have got this far: 1). Data will be stored in a vector of...
3
by: BobforeApples | last post by:
Hi All, I was trying to apply databinding to a custom collection as in the MSDN Magazine article found in the August, 2005 issue. After converting the code in the article to C# and applying it to...
2
by: AJ | last post by:
Hi all, I am posting from the web based forum on msdn.com. My question is, how do i create the heirarchical table like controls that this forum uses to display posts. Any tutorials, links...
2
by: Charlie | last post by:
Hi: I have one-to-many relation (customer > invoice > invoice_items) that I would like to display on web page using Repeater control. Can the control be bound to a heirarchical dataset to...
1
by: Prawin | last post by:
Hi, My Requirement is to display the records from the database in Tree Like structure but I cannot use TreeView Control of ASP.Net 2.0 becuase I need to display multiple columns so Iam suppose to...
1
by: kikisan | last post by:
I am developing a windows service which utilizes the following classes: interface IPersistable; abstract class PersistableObject : IPersistable;
1
by: jehugaleahsa | last post by:
Hello: I am sure this is a common need, so I hope I can be brief. I have a heirarchical database setup such that one customer can have multiple contracts and those contracts can have multiple...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.