O'Reilly logo

C# in a Nutshell by Peter Drayton, Ted Neward, Ben Albahari

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 11. Serialization

The .NET Framework includes extensive support for serialization and deserialization, allowing clients to explicitly and implicitly serialize object instances and arbitrarily complex object graphs, and allowing types a wide degree of control over how and where they are serialized and deserialized.

This chapter introduces the support for object serialization and deserialization that is built-in to the .NET Framework, and shows how clients and objects can participate in the serialization and deserialization process. Unless otherwise stated, the types mentioned in this chapter all exist in the System or System.Runtime.Serialization namespaces.

What Is Serialization?

Some types are like mosquitoes: once instantiated, they live a short life near to where they were born, and then die quietly. Types such as these don’t store important non-transient data and are used by clients in the same context they were created in. These types are trivial, and generally don’t need serialization. However, many important types are not like this, storing data that needs to be persisted to some backing store (e.g. a database, file, or network), or being passed back and forth between different contexts as parameters in method calls. These types need to support serialization.

Serialization is the act of taking an in-memory object or object graph and flattening it into a stream of bytes that may be stored or transmitted. Deserialization works in reverse, taking a stream of bytes and re-constituting ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required