When I generate custom classes using my own CodeSmith templates, I do not add the Serializable Attribute ([Serializable]) to the entity or collection classes by default.
Lately, it seems that I am adding the Serializable Attribute more often. I normally do this when I am storing the entity/collection in either ViewState or in a Session variable. I began wondering if I should add the Serializable Attribute by default. What could the negative effects be? After reading the documentation for the SerializableAttribute Class on MSDN, it seems the only side effect that I should be aware of is that classes marked as Serializable cannot be inherited. I can live with that.
Now I need to decide if I should edit my CodeSmith templates to include the Serializable Attribute in all of the entity and collection classes it generates. Hmmm...
For more information on what Serialization means check out the System.Runtime.Serialization Namespace documentation. Here is a good summary from the article:
Serialization is the process of converting an object or a graph of
objects into a linear sequence of bytes for either storage or transmission to
another location. Deserialization is the process of taking in stored information
and recreating objects from it.