Serialization - Using inherited Classes

G

Guest

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
{
....
}
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top