Technical Articles

What is Serialization??

0 0
Serialization is the process of converting an object into a stream of bytes in order 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. The reverse process is called deserialization.


The easiest way to make a class serializable is to mark it with the Serializable attribute as follows.

[Serializable]
public class MyObject {
  public int n1 = 0;
  public int n2 = 0;
  public String str = null;
}
.NET offers 2 serializers: binary, SOAP, XML. The difference between binary and SOAP is:
 
binary is more efficient (time and memory used)
binary is not human-readable. SOAP isn't much better.
 
XML is slightly different:
 
it lives in System.Xml.Serialization
it uses [XmlIgnore] instead of [NonSerialized] and ignores [Serializable]
it doesn't serialize private class members
It is important to note that the Serializable attribute cannot be inherited.
http://msdn.microsoft.com/en-us/library/ms233843.aspx
http://msdn.microsoft.com/en-us/library/4abbf6k0(v=vs.110).aspx
http://www.codeproject.com/Articles/1789/Object-Serialization-using-C
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
× How can I help you?