The System.Runtime.Serialization namespace contains classes that can be used for serializing and deserializing objects.
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 re-creating objects from it.
Data Contract Classes
Two notable classes of this namespace are the DataContractAttribute and DataMemberAttribute attribute classes. Apply these attributes (to classes and class members, respectively) when creating Silverlight 5 clients to specify which members of a class contain data that must be serialized. You can also apply the EnumMemberAttribute to enumeration members to control the XML generated. And apply the CollectionDataContractAttribute to collection classes to control the XML elements generated from collections.
Data Contract Serialization
To create code from XSD schema documents, use the XsdDataContractImporter. With this class, you can read an XSD document, and generate System.CodeDom components that can be used to generate Visual Basic or Visual C# source code tailored to handling XML data.
Serialization without an Explicit Data Contract
Silverlight 5 also supports a simplified opt-out model for serialization, where these attributes can be omitted from the type and the members of the type to be serialized. The data contract is implicit in the sense that the visibility modifiers (public, private) used by the type determines whether it and its members are included in the data contract. In this model, the name of a member is used to identify it in the serialized representation. A new IgnoreDataMemberAttribute attribute can be used to opt-out a member that is public when required.
For more information about
serialization with an explicit data contract, see Silverlight Serialization.
|CollectionDataContractAttribute||When applied to a collection type, enables custom specification of the collection item elements. This attribute can be applied only to types that are recognized by the DataContractSerializer as valid, serializable collections.|
|ContractNamespaceAttribute||Specifies the CLR namespace and XML namespace of the data contract.|
|DataContractAttribute||Specifies that the type defines or implements a data contract and can be serialized by a serializer, such as the DataContractSerializer.|
|DataContractSerializer||Serializes and deserializes an instance of a type into an XML stream or document using a supplied data contract. This class cannot be inherited.|
|DataMemberAttribute||When applied to the member of a type, specifies that the member is part of a data contract and is serializable by the DataContractSerializer.|
|EnumMemberAttribute||Specifies that the field is an enumeration member and should be serialized.|
|IgnoreDataMemberAttribute||When applied to the member of a type, specifies that the member is not part of a data contract and is not serialized.|
|InvalidDataContractException||The exception that is thrown when the DataContractSerializer encounters an invalid data contract during serialization and deserialization.|
|KnownTypeAttribute||Specifies types that should be recognized by the DataContractSerializer when serializing or deserializing a given type.|
|OnDeserializedAttribute||When applied to a method, specifies that the method is called immediately after deserialization of the object.|
|OnDeserializingAttribute||When applied to a method, specifies that the method is called during deserialization of an object.|
|OnSerializedAttribute||When applied to a method, specifies that the method is called after serialization of an object graph.|
|OnSerializingAttribute||When applied to a method, specifies that the method is called before serialization of an object.|
|SerializationException||The exception thrown when an error occurs during serialization or deserialization.|
|XmlObjectSerializer||Provides the base class used to serialize objects as XML streams or documents. This class is abstract.|
|StreamingContext||Describes the source and destination of a given serialized stream, and provides an additional caller-defined context.|
|StreamingContextStates||Defines a set of flags that specifies the source or destination context for the stream during serialization.|