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

Serialization and derived classes

Can anybody point me towards a sample of serializing/deserializing specific
classes that are derived from a generic class? Is it necessary to use a
switch statement or can it be done in a more extensible way?
Nov 16 '05 #1
5 7139
Stuart,

You shouldn't have a problem with this. The type information is stored
in the stream, and the formatter should be able to pick this up.

All you have to do in your derived class is attach the Serializable
attribute and optionally implement the ISerializable interface.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"StuartM miles @amsjv.com>" <"stuart<dot> wrote in message
news:41**********@baen1673807.greenlnk.net...
Can anybody point me towards a sample of serializing/deserializing
specific
classes that are derived from a generic class? Is it necessary to use a
switch statement or can it be done in a more extensible way?

Nov 16 '05 #2
Stuart,

You shouldn't have a problem with this. The type information is stored
in the stream, and the formatter should be able to pick this up.

All you have to do in your derived class is attach the Serializable
attribute and optionally implement the ISerializable interface.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"StuartM miles @amsjv.com>" <"stuart<dot> wrote in message
news:41**********@baen1673807.greenlnk.net...
Can anybody point me towards a sample of serializing/deserializing
specific
classes that are derived from a generic class? Is it necessary to use a
switch statement or can it be done in a more extensible way?

Nov 16 '05 #3
On Tue, 9 Nov 2004 13:01:09 -0500, Nicholas Paldino [.NET/C# MVP] wrote:
Stuart,

You shouldn't have a problem with this. The type information is stored
in the stream, and the formatter should be able to pick this up.

All you have to do in your derived class is attach the Serializable
attribute and optionally implement the ISerializable interface.

Hope this helps.


Perhaps I'm making this harder than it really is. AIUI when I deserialize
the object I have to cast it to its correct type, if I don't know which
derived class I've got how do I do the cast?
Nov 16 '05 #4
On Tue, 9 Nov 2004 13:01:09 -0500, Nicholas Paldino [.NET/C# MVP] wrote:
Stuart,

You shouldn't have a problem with this. The type information is stored
in the stream, and the formatter should be able to pick this up.

All you have to do in your derived class is attach the Serializable
attribute and optionally implement the ISerializable interface.

Hope this helps.


Perhaps I'm making this harder than it really is. AIUI when I deserialize
the object I have to cast it to its correct type, if I don't know which
derived class I've got how do I do the cast?
Nov 16 '05 #5
Hi Stuart,

Do you really need to know the type of object if they all derive from the
same base class? Surely polymorphism will take care the various
sub-classes?

If you really do need to know the type you could check with the 'is' keyword
and cast accordingly, but that's ugly and you'll have to update it for any
new sub-classes created.

Though it must be said I'm no serialization expert so there may be a cleaner
way...

--Liam.

"StuartM miles @amsjv.com>" <"stuart<dot> wrote in message
news:41**********@baen1673807.greenlnk.net...
On Tue, 9 Nov 2004 13:01:09 -0500, Nicholas Paldino [.NET/C# MVP] wrote:
Stuart,

You shouldn't have a problem with this. The type information is stored in the stream, and the formatter should be able to pick this up.

All you have to do in your derived class is attach the Serializable
attribute and optionally implement the ISerializable interface.

Hope this helps.


Perhaps I'm making this harder than it really is. AIUI when I deserialize
the object I have to cast it to its correct type, if I don't know which
derived class I've got how do I do the cast?

Nov 16 '05 #6

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

Similar topics

37
by: Ben | last post by:
Hi, there. Recently I was working on a problem where we want to save generic closures in a data structure (a vector). The closure should work for any data type and any method with pre-defined...
3
by: Aaron Clamage | last post by:
Hi, I'm not sure that if this is the right forum, but any help would be greatly appreciated. I am porting some java serialization code to c# and I can't figure out the correct way to do it. ...
2
by: Hasani | last post by:
If I have a base class that is derived from many classes, and I want to make all the classes serializable. Is there a way I can do this from the base class or must I add to every class, even if...
4
by: Mark Sizer | last post by:
Hi people, I'm having trouble trying to achieve something in C# and win forms, and am looking for a little advice if anyone has a moment. I've got two classes: 1) a base class 2) a derived...
10
by: Michael Maes | last post by:
Hi, I have a BaseClass from which many Classes Derive. In short: the BaseClass provides the functionalities (Methods) and the Derived Classes extend it with Properties. One of the (Base)...
6
by: John Glover | last post by:
I'm having a very strange problem with XML serialization. I'm writing web services which pass instances of various classes back and forth as parameters and return values of web methods. The...
4
by: Chris | last post by:
Hi all, I can serialize and deserialize a single class, but I'm wondering if it's possible to serialize/deserialize different class types in the same file? For example, I have a base class, and...
11
by: William | last post by:
I'm looking for an example that would show how to serialize a c++ object at it's simplest w/o using any other api's. I have a class that I want to serialize and then pass to my obj-c class so I can...
1
by: MindWrapper | last post by:
boost serialization of polymorph classes from DLLs Folks, Let's consider following code -------------------------------- // base.h // abstract base class class IBase {
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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...

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.