Export (0) Print
Expand All
8 out of 9 rated this helpful - Rate this topic

System.Runtime.Serialization Namespace

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 recreating objects from it.

The ISerializable interface provides a way for classes to control their own serialization behavior. Classes in the System.Runtime.Serialization.Formatters namespace control the actual formatting of various data types encapsulated in the serialized objects.

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 Windows Communication Foundation (WCF) services 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 generated XML. And apply the CollectionDataContractAttribute to collection classes to control the XML elements generated from collections (such as key name and value name for).

Data Contract Serialization

Another major class is the DataContractSerializer. Use this class to serialize or deserialize instances of classes that have the DataContractAttribute and DataMemberAttribute applied.

To create code from XSD schema documents, use the XsdDataContractImporter. With the 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.

Conversely, to create XSD schema documents from CLR classes, use the XsdDataContractExporter. You can provide an assembly as input, and export XSD schemas that can be used by other services to create interoperable XML messages.

  ClassDescription
Public classCollectionDataContractAttributeWhen 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.
Public classContractNamespaceAttributeSpecifies the CLR namespace and XML namespace of the data contract.
Public classDataContractAttributeSpecifies that the type defines or implements a data contract and is serializable by a serializer, such as the DataContractSerializer. To make their type serializable, type authors must define a data contract for their type.
Public classDataContractSerializerSerializes and deserializes an instance of a type into an XML stream or document using a supplied data contract. This class cannot be inherited.
Public classDataMemberAttributeWhen applied to the member of a type, specifies that the member is part of a data contract and is serializable by the DataContractSerializer.
Public classEnumMemberAttributeSpecifies that the field is an enumeration member and should be serialized.
Public classExportOptionsRepresents the options that can be set for an XsdDataContractExporter.
Public classExtensionDataObjectStores data from a versioned data contract that has been extended by adding new members.
Public classFormatterProvides base functionality for the common language runtime serialization formatters.
Public classFormatterConverterRepresents a base implementation of the IFormatterConverter interface that uses the Convert class and the IConvertible interface.
Public classFormatterServicesProvides static methods to aid with the implementation of a Formatter for serialization. This class cannot be inherited.
Public classIgnoreDataMemberAttributeWhen applied to the member of a type, specifies that the member is not part of a data contract and is not serialized.
Public classImportOptionsRepresents the options that can be set on an XsdDataContractImporter.
Public classInvalidDataContractExceptionThe exception that is thrown when the DataContractSerializer or NetDataContractSerializer encounters an invalid data contract during serialization and deserialization.
Public classKnownTypeAttributeSpecifies types that should be recognized by the DataContractSerializer when serializing or deserializing a given type.
Public classNetDataContractSerializerSerializes and deserializes an instance of a type into XML stream or document using the supplied .NET Framework types. This class cannot be inherited.
Public classObjectIDGeneratorGenerates IDs for objects.
Public classObjectManagerKeeps track of objects as they are deserialized.
Public classOnDeserializedAttributeWhen applied to a method, specifies that the method is called immediately after deserialization of the object.
Public classOnDeserializingAttributeWhen applied to a method, specifies that the method is called during deserialization of an object.
Public classOnSerializedAttributeWhen applied to a method, specifies that the method is called after serialization of an object graph.
Public classOnSerializingAttributeWhen applied to a method, specifies that the method is called before serialization of an object.
Public classOptionalFieldAttributeSpecifies that a field can be missing from a serialization stream so that the BinaryFormatter and the SoapFormatter does not throw an exception.
Public classSerializationBinderAllows users to control class loading and mandate what class to load.
Public classSerializationExceptionThe exception thrown when an error occurs during serialization or deserialization.
Public classSerializationInfoStores all the data needed to serialize or deserialize an object. This class cannot be inherited.
Public classSerializationInfoEnumeratorProvides a formatter-friendly mechanism for parsing the data in SerializationInfo. This class cannot be inherited.
Public classSerializationObjectManagerManages serialization processes at run time. This class cannot be inherited.
Public classSurrogateSelectorAssists formatters in selection of the serialization surrogate to delegate the serialization or deserialization process to.
Public classXmlObjectSerializerProvides the base class used to serialize objects as XML streams or documents. This class is abstract.
Public classXmlSerializableServicesContains methods for reading and writing XML.
Public classXsdDataContractExporterAllows the transformation of a set of .NET Framework types that are used in data contracts into an XML schema file (.xsd).
Public classXsdDataContractImporterAllows the transformation of a set of XML schema files (.xsd) into common language runtime (CLR) types.
  StructureDescription
Public structureSerializationEntryHolds the value, Type, and name of a serialized object.
Public structureStreamingContextDescribes the source and destination of a given serialized stream, and provides an additional caller-defined context.
  InterfaceDescription
Public interfaceIDataContractSurrogateProvides the methods needed to substitute one type for another by the DataContractSerializer during serialization, deserialization, and export and import of XML schema documents (XSD).
Public interfaceIDeserializationCallbackIndicates that a class is to be notified when deserialization of the entire object graph has been completed.
Public interfaceIExtensibleDataObjectProvides a data structure to store extra data encountered by the XmlObjectSerializer during deserialization of a type marked with the DataContractAttribute attribute.
Public interfaceIFormatterProvides functionality for formatting serialized objects.
Public interfaceIFormatterConverterProvides the connection between an instance of SerializationInfo and the formatter-provided class best suited to parse the data inside the SerializationInfo.
Public interfaceIObjectReferenceIndicates that the current interface implementer is a reference to another object.
Public interfaceISerializableAllows an object to control its own serialization and deserialization.
Public interfaceISerializationSurrogateImplements a serialization surrogate selector that allows one object to perform serialization and deserialization of another.
Public interfaceISurrogateSelectorIndicates a serialization surrogate selector class.
  EnumerationDescription
Public enumerationStreamingContextStatesDefines a set of flags that specifies the source or destination context for the stream during serialization.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.