Serialization Support in the Framework
The .NET Framework includes extensive support for both serialization
and deserialization, both from the perspective of clients wanting to serialize
and deserialize objects, and from the perspective of types wanting some control
over how and where they are serialized. This support is found in two sets
of namespaces: System.Runtime.Serialization.*
and System.Xml.Serialization.*
Each of these namespaces includes a suite of types that, together with
your types, form a serialization “engine,” which has the ability
to serialize one or more objects into a stream of some kind. Additionally, each
of these namespaces supports XML as a serialization format (the System.Runtime.Serialization.*
namespaces also support a binary serialization format).
The primary differences between the two serialization engines are that the one contained in the
System.Runtime.Serialization.*
namespaces supports
arbitrary object graphs and can serialize any .NET type using SOAP
section 5 encoding. However, this engine produces XML that is very
CLR-centric, describing primitive types using XML namespaces and
schemas that assume the reader understands the CLR type system. On the
other hand, the serialization engine contained in the
System.Xml.Serialization.*
namespaces produces very clean XSD schemas and matching XML instances, describing primitive types in terms of XSD data types wherever possible. However, it cannot handle arbitrary object graphs, and in some cases doesn’t ...
Get C# in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.