O'Reilly logo

C# 5.0 Programmer's Reference by Rod Stephens

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 25 Serialization

What’s in This Chapter

  • Serialization and deserialization
  • XML, JSON, and binary serialization
  • Using attributes to control serialization

Wrox.com Downloads for This Chapter

Please note that all the code examples for this chapter are available as a part of this chapter’s code download on the book’s website at www.wrox.com/go/csharp5programmersref on the Download Code tab.

Serialization is the process of converting one or more objects into a serial, stream-like format, often text. Deserialization is the reverse: restoring an object from its serialization.

Like the XML files described in the preceding chapter, serialization gives you a portable way to store data. You can serialize an object and send the serialization to another program, and then that program can deserialize the object.

You can also use serialization to allow a program to save and restore its state. For example, a drawing program might build a complicated data structure containing the objects the user drew. To save the drawing, the program could write the data structure’s serialization into a file. Later it could reload the serialization and display the objects.

The objects serialized can be relatively simple, such as a Customer or Person object, or they can be complex data structures including objects that have references to other objects. For example, you could serialize a CustomerOrder object that includes an array of Order objects each containing a list of OrderItem objects.

For something ...

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