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

Serialization - Using inherited Classes

In the current project that I am planning i am thinking of serializing the
objects to save as binary files. The question I have is with inheriting
classes.

If I have 1 base class and 2 classes that inherit from it. How would I
configure them for serialization. Do I just put the Serialized setting on the
2 classes or do I also have to put it on the base class.

ie.

class IBaseClass
{
....
}

[Serializable]
class FirstClass : IBaseClass
{
....
}

[Serializable]
class SecondClass : IBaseClass
{
....
}

or.

[Serializable]
class IBaseClass
{
....
}

[Serializable]
class FirstClass : IBaseClass
{
....
}

[Serializable]
class SecondClass : IBaseClass
{
....
}
Nov 16 '05 #1
1 1845
Hi Glenn,

Generally, for serialization to work you need to apply the [Serializable]
attrbute to both the base class and the subclasses which needs serialization.

HTH

Cheers,
Madhu

MVP - C# | MCSD.NET

"Glenn Wilson" wrote:
In the current project that I am planning i am thinking of serializing the
objects to save as binary files. The question I have is with inheriting
classes.

If I have 1 base class and 2 classes that inherit from it. How would I
configure them for serialization. Do I just put the Serialized setting on the
2 classes or do I also have to put it on the base class.

ie.

class IBaseClass
{
...
}

[Serializable]
class FirstClass : IBaseClass
{
...
}

[Serializable]
class SecondClass : IBaseClass
{
...
}

or.

[Serializable]
class IBaseClass
{
...
}

[Serializable]
class FirstClass : IBaseClass
{
...
}

[Serializable]
class SecondClass : IBaseClass
{
...
}

Nov 16 '05 #2

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

Similar topics

0
by: ron | last post by:
This is as clean as i can get it. Thanks Ron This is the base class that serializes and desrializes the class objects it also provides abstract methodes that are called from its inherited...
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. ...
1
by: David C | last post by:
I am new to Serialization, so please bear with me. I have a class inherited from a non-serializable class. My goal is to serialize an instance of it to XML and I am only interested in the...
1
by: Tamir Khason | last post by:
I have a base class MyBaseFoo with some properties, methods etc. I have some derived classes, implements small part of MyBaseFoo and a lot of their own. In order to ensure proper deserialization...
2
by: tony lock | last post by:
I have a class inherited from Control, which I want to serialize, since Control is not Serializable, I have had to implement ISerializable. This works but I now want to inherit this base class into...
10
by: SStory | last post by:
My app is near completed for the basic feature of version 1.0. I have an extensive object model and I now want to persist my objects using serialization. I have chosen binaryformatter to...
4
by: mijalko | last post by:
Hi, I have inherited my class from System.Drawing.Printing.PrintDocument and I wish to serialize this object using XmlSerializer. And I get exception "There was an error reflecting type ...". If I...
0
by: bharathreddy | last post by:
Before going to that i want to say few thing on serialization : Serialization is the process of converting an object into a form that can be readily transported. For example, you can serialize an...
1
by: kikisan | last post by:
I am developing a windows service which utilizes the following classes: interface IPersistable; abstract class PersistableObject : IPersistable;
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: 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
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
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.