473,399 Members | 2,858 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,399 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 7143
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
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.