Description = 'Wrox.com Web site',
NextURL = null
};
//---link the first BookMark to the next---
bm1.NextURL = bm2;
}
To prove that the object is serialized correctly, you deserialize the memory stream (that is, 'unflatten' the data) and assign it back to a BookMark
object:
static void Main(string[] args) {
BookMark bm1, bm2;
bm1 = new BookMark {
URL = 'http://www.amazon.com',
Description = 'Amazon.com Web site'
};
bm2 = new BookMark() {
URL = 'http://www.wrox.com',
Description = 'Wrox.com Web site',
NextURL = null
};
//---link the first BookMark to the next---
bm1.NextURL = bm2;
//========Binary Serialization=========
//---serializing an object graph into a memory stream---
MemoryStream ms = Serialize(bm1);
}
Here is the definition for the DeSerialize()
function:
static void Main(string[] args) {
//...
}
static MemoryStream Serialize(BookMark bookMark) {
//...
}
To display the values of the deserialized BookMark object, you can print out them out like this:
static void Main(string[] args) {
BookMark bm1, bm2;
bm1 = new BookMark {
URL = 'http://www.amazon.com',
Description = 'Amazon.com Web site'
};
bm2 = new BookMark() {
URL = 'http://www.wrox.com',
Description = 'Wrox.com Web site',
NextURL = null
};
//---link the first BookMark to the next---
bm1.NextURL = bm2;
}
To prove that the object is serialized correctly, you deserialize the memory stream (that is, 'unflatten' the data) and assign it back to a BookMark
object:
static void Main(string[] args) {
BookMark bm1, bm2;
bm1 = new BookMark {
URL = 'http://www.amazon.com',
Description = 'Amazon.com Web site'
};
bm2 = new BookMark() {
URL = 'http://www.wrox.com',
Description = 'Wrox.com Web site',
NextURL = null
};
//---link the first BookMark to the next---
bm1.NextURL = bm2;
//========Binary Serialization=========
//---serializing an object graph into a memory stream---
MemoryStream ms = Serialize(bm1);
//---deserializing a memory stream into an object graph---
BookMark bm3 = Deserialize(ms);
}
If the objects are serialized and deserialized correctly, the output is as shown in Figure 11-12.

Figure 11-12
But what does the binary stream look like? To answer that question, take a look at the c: BookMarks.dat
file that you have created in the process. To view the binary file, simply drag and drop the BookMarks.dat
file into Visual Studio 2008. You should see something similar to Figure 11-13.

Figure 11-13
A few observations are worth noting at this point: