Answered by:
If a base class is marked as [Serializable] will the dervied class also be serializable?

Question
-
If I derive a class from a base class that is decorated with the [Serializable] attribute, will the entire derived class be serializable or will the derived class also need to be decorated?
For example:
[Serializable] public class MyBase { public int Id { get; set; } } public class MyDerived : MyBase { public string Name { get; set; } }
IOW, Do I also need to add [Serializable] to MyDerived or is it implied from the parent?
- Edited by BillyM2010 Tuesday, July 10, 2012 7:26 PM
Answers
-
You need to put Serialization on top of derived class as well.
Read for more: http://stackoverflow.com/questions/754850/serialization-in-c-sharp-with-a-derived-class
Mitja
- Proposed as answer by Jason Dot Wang Thursday, July 12, 2012 7:14 AM
- Marked as answer by Jason Dot Wang Wednesday, July 18, 2012 8:07 AM
-
The following thread on Stack Overflow should provide some clarification: http://stackoverflow.com/questions/182873/serializable-inheritance
David Downing... If this answers your question, please Mark as the Answer. If this post is helpful, please vote as helpful.
- Proposed as answer by Jason Dot Wang Thursday, July 12, 2012 7:14 AM
- Marked as answer by Jason Dot Wang Wednesday, July 18, 2012 8:07 AM
-
No. You have to Write [Serializable] on the top of drived class as well.
Thanks,
Kapul
- Proposed as answer by Jason Dot Wang Thursday, July 12, 2012 7:14 AM
- Marked as answer by Jason Dot Wang Wednesday, July 18, 2012 8:07 AM
All replies
-
The following thread on Stack Overflow should provide some clarification: http://stackoverflow.com/questions/182873/serializable-inheritance
David Downing... If this answers your question, please Mark as the Answer. If this post is helpful, please vote as helpful.
- Proposed as answer by Jason Dot Wang Thursday, July 12, 2012 7:14 AM
- Marked as answer by Jason Dot Wang Wednesday, July 18, 2012 8:07 AM
-
You need to put Serialization on top of derived class as well.
Read for more: http://stackoverflow.com/questions/754850/serialization-in-c-sharp-with-a-derived-class
Mitja
- Proposed as answer by Jason Dot Wang Thursday, July 12, 2012 7:14 AM
- Marked as answer by Jason Dot Wang Wednesday, July 18, 2012 8:07 AM
-
No. You have to Write [Serializable] on the top of drived class as well.
Thanks,
Kapul
- Proposed as answer by Jason Dot Wang Thursday, July 12, 2012 7:14 AM
- Marked as answer by Jason Dot Wang Wednesday, July 18, 2012 8:07 AM