.NET Development Foundation | |
---|---|
Exam objective:Implementing serialization and input/output functionality in a .NET Framework application
![]() | Wikipedia has related information atserialization |
Wikipedia's definition for serialization is : "in the context of data storage and transmission, serialization is the process of saving an object onto a storage medium (such as a file, or a memory buffer) or to transmit it across a network connection link in binary form".
The problem that is addressed here is that an object is created by a running process and is thus bound to the lifetime of that process instance. If for whatever reason, and there can be many, you want to "transport" the object in the context of another process instance you've got a problem, that you solve by "saving" the state of you object in the original process and "restoring" it in the destination process. This "saving" part is called serialization and the "restoring" part is called deserialization.
An object is serializable if its class name is prefixed with the [Serializable] attribute.
One can use theBinaryFormatter class to serialize an object. To serialize, use the BinaryFormatter's Serialize() method which takes a stream and a serializable object as parameters. To deserialize, use the BinaryFormatter's Deserialize() method which takes a stream as a parameter and returns a object that can be cast back to the original object type. Remember to close streams after you use them by calling the stream's Close() method.
One can use theXmlSerializer class to serialize an object. To serialize, use the XmlSerializer's Serialize() method which takes a stream and a serializable object as parameters. To deserialize, use the XmlSerializer's Deserialize() method which takes a stream as a parameter and returns a object that can be cast back to the original object type. Remember to close streams after you use them by calling the stream's Close() method.
For an overview of XML and SOAP serialization seeMSDN
The ISerializable interface allows an object to control its own serialization and deserialization.
A formatter is used to serialize objects into streams.
For a general discussion on IsolatedStorage tasks seeMSDN
Exam objective:Serialize or deserialize an object or an object graph by using runtime serialization techniques.
(Refer System.Runtime.Serialization namespace)
IDeserializationCallback interface -MSDN
IFormatter interface and IFormatterConverter interface
ISerializable interface -MSDN
OnDeserializedAttribute class and OnDeserializingAttribute class
OnSerializedAttribute class and OnSerializingAttribute class
OptionalFieldAttribute class -MSDN
SerializationEntry structure -MSDN
SerializationInfo class -MSDN
ObjectManager class -MSDN
Formatter class -MSDN
FormatterConverter class -MSDN
FormatterServices class -MSDN
StreamingContext structure -MSDN
Exam objective:Control the serialization of an object into XML format by using the System.Xml.Serialization namespace.
XmlSerializer class -MSDN
Control serialization by using serialization attributes -MSDN
Implement XML Serialization interfaces to provide custom formatting for XML serialization -MSDN
Delegates and event handlers are provided by the System.Xml.Serialization namespace -MSDN
Exam objective:Implement custom serialization formatting by using the Serialization Formatter classes.
SoapFormatter class -MSDN
BinaryFormatter class -MSDN
Exam objective:Access files and folders by using the File System classes.
(Refer System.IO namespace)
File class and FileInfo class
Directory class and DirectoryInfo class
DriveInfo class and DriveType enumeration
FileSystemInfo class and FileSystemWatcher class
Example: FileSystemWatcher w = new FileSystemWatcher(); w.Filter = "*.txt"; w.Path = @"C:\Windows";
Path class -MSDN
ErrorEventArgs class and ErrorEventHandler delegate
RenamedEventArgs class and RenamedEventHandler delegate
Exam objective:Manage byte streams by using Stream classes.
(Refer System.IO namespace)
FileStream class -MSDN
Stream class -MSDN
MemoryStream class -MSDN
BufferedStream class -MSDN
Exam objective:Manage the .NET Framework application data by using Reader and Writer classes.
(Refer System.IO namespace)
StringReader class and StringWriter class -MSDN andMSDN
TextReader class and TextWriter class
StreamReader class and StreamWriter class -MSDN andMSDN
BinaryReader class and BinaryWriter class
Exam objective:Compress or decompress stream information in a .NET Framework application and improve the security of application data by using isolated storage.
(Refer System.IO.Compression namespace)
(Refer System.IO.IsolatedStorage namespace)
IsolatedStorageFile class -MSDN
IsolatedStorageFileStream class -MSDN
DeflateStream class -MSDN
GZipStream class -MSDN