Using Reflection to Serialize Types

One of the most prominent uses for reflection is serialization. Serialization is the process of turning an object into a stream of bytes that can be stored or transferred “elsewhere” and then used to reconstruct the object. You obviously cannot take an existing object and directly transfer it to another machine and expect it to work. Certain addresses and handles only correspond to memory on one machine or, for that matter, one process. In the past, MFC had a facility whereby an object could serialize and deserialize itself. The programmer decided which fields needed to be serialized through the code. Using reflection, it was possible to assist the programmer in serializing an object. The programmer no longer ...

Get .NET Common Language Runtime Unleashed 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.