Serialization in .NET
Serialization
Many applications need to store or transfer data stored in
objects. serialization techniques makes this task simple.These techniques convert
objects into binary, Simple Object Access Protocol (SOAP),or XML documents that
can be easily stored, transferred, and retrieved.
Serializing is
the process of converting an object into a linear sequence of bytes that can be
stored or transferred.
Deserializing
is the process of converting a previously serialized sequence of bytes
into an object.
namespace : System.Runtime.Serialization
How to Serialize an Object
1. Create a stream
object to hold the serialized output.
2. Create a BinaryFormatter object
(located in System.Runtime.Serialization.Formatters.Binary).
3. Call the BinaryFormatter.Serialize method to serialize the object, and output the result to
the stream.
How to Deserialize an Object
1. Create a stream
object to read the serialized output.
2. Create a BinaryFormatter object.
3. Create a new
object to store the deserialized data.
4. Call the BinaryFormatter.Deserialize method to deserialize the object, and cast it to the
correct type.
How to Use XML to Serialize an Object
1. Create a stream, TextWriter,
or XmlWriter object
to hold the serialized output.
2. Create an XmlSerializer object
(in the System.Xml.Serialization namespace) by
passing it the type of object you plan to serialize.
3. Call the XmlSerializer.Serialize method to serialize the object and output the results to
the stream.
How to Use XML to Deserialize an Object
1. Create a stream, TextReader, or
XmlReader object to read the serialized input.
2. Create an XmlSerializer object
(in the System.Xml.Serialization namespace) by passing it the type of object you plan to
deserialize.
3. Call the XmlSerializer.Deserialize method to deserialize the object, and cast it to the
correct type.
0 comments:
Post a Comment