Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is serializable attribute needed in concrete C# class?

In C#, consider we have a generic class and a concrete class

[Serializable]
public class GenericUser
{ ...

[Serializable]
public class ConcreteUser : GenericUser
{ ...

is it necessary to mark ConcreteUser as [Serializable] or inheritance will take care of it?

like image 540
Junior Mayhé Avatar asked Nov 15 '10 12:11

Junior Mayhé


People also ask

What does Serializable attribute do?

Allows an object to control its own serialization and deserialization.

Why we use Serializable attribute in c#?

Serialization is the process of converting an object into a stream of bytes to store the object or transmit it to memory, a database, or a file. Its main purpose is to save the state of an object in order to be able to recreate it when needed.


1 Answers

Inherited is set to false with the [AttributeUsage] of SerializableAttribute, so yes, you need to set it on the concrete class.

See http://msdn.microsoft.com/en-us/library/system.serializableattribute.aspx for more information.

like image 196
Pieter van Ginkel Avatar answered Sep 22 '22 15:09

Pieter van Ginkel