System.Runtime.Serialization
Namespace

System.Runtime.Serialization 命名空间包含可用于将对象序列化和反序列化的类。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.

本文内容

类

当应用于集合类型时，可用来对集合项元素进行自定义指定。When applied to a collection type, enables custom specification of the collection item elements.此属性只能应用于被 DataContractSerializer 视为有效的可序列化集合的类型。This attribute can be applied only to types that are recognized by the DataContractSerializer as valid, serializable collections.

指定该类型要定义或实现一个数据协定，并可由序列化程序（如 DataContractSerializer）进行序列化。Specifies 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.

使用提供的 .NET Framework 类型，将类型实例序列化和反序列化为 XML 流或文档。Serializes and deserializes an instance of a type into XML stream or document using the supplied .NET Framework types.此类不能被继承。This class cannot be inherited.

如果将对象图中的对象应用于某方法，则应指定在反序列化该对象图后立即调用该方法。When applied to a method, specifies that the method is called immediately after deserialization of an object in an object graph.相对于关系图中的其他对象，该反序列化的顺序是不确定的。The order of deserialization relative to other objects in the graph is non-deterministic.

当应用于方法时，指定在反序列化对象关系图中的对象期间调用该方法。When applied to a method, specifies that the method is called during deserialization of an object in an object graph.相对于关系图中的其他对象，该反序列化的顺序是不确定的。The order of deserialization relative to other objects in the graph is non-deterministic.

当应用于方法时，指定在序列化对象关系图中的对象之后调用该方法。When applied to a method, specifies that the method is called after serialization of an object in an object graph.相对于关系图中的其他对象，序列化的顺序是不确定的。The order of serialization relative to other objects in the graph is non-deterministic.

当应用于方法时，指定在序列化对象关系图中的对象期间调用该方法。When applied to a method, specifies that the method is during serialization of an object in an object graph.相对于关系图中的其他对象，序列化的顺序是不确定的。The order of serialization relative to other objects in the graph is non-deterministic.

接口

提供 DataContractSerializer 在序列化、反序列化以及导出和导入 XML 架构文档 (XSD) 的过程中将一种类型替换为另一种类型所需的方法。Provides the methods needed to substitute one type for another by the DataContractSerializer during serialization, deserialization, and export and import of XML schema documents (XSD).

指示在完成整个对象图形的反序列化时通知类。Indicates that a class is to be notified when deserialization of the entire object graph has been completed.注意当用 XmlSerializer (System.Xml.Serialization.XmlSerializer) 反序列化时，不调用此接口。Note that this interface is not called when deserializing with the XmlSerializer (System.Xml.Serialization.XmlSerializer).

提供构造用于扩展 DataContractSerializer 的序列化代理项所需的方法。Provides the methods needed to construct a serialization surrogate that extends the DataContractSerializer.在序列化和反序列化期间，使用序列化代理项将一种类型替换为另一类型。A serialization surrogate is used during serialization and deserialization to substitute one type for another.