Serialization - Using inherited Classes

  • Thread starter Thread starter Guest
  • Start date Start date
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
{
....
}
 
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
 
Back
Top