Implementing Object Serialization and Deserialization
Applies to: Visual Studio .NET 2002, Visual Studio .NET 2003, Visual Studio 2005, Visual Studio 2008
Serialization is the term used for the act of persisting (saving)
an object to a storage medium - a file, a database or even main memory. The purpose is to be able to re-create an object instance that can be considered
identical to the original (through a process called deserialization) and later use it into the same or another application
domain. The .NET Framework knows how to serialize basic
data types, but if you want to serialize custom fields in your own types then you must
implement the ISerializable interface and a specialized deserialization
constructor.
To implement serialization and deserialization code for an already defined type:
-
Open the Visual Basic or C# component containing the type you want
to implement serialization and deserialization code for and place the cursor
inside that type's code.
-
In the CodeSMART main menu, select the Implement Object Serialization
and Deserialization entry from the Code Builder Tools popup menu, Implement Advanced Code secondary popup, or
choose the Object Serialization and Deserialization entry from the Implement
toolbar popup (quick toolbar and menu
references are available).
The Implement Object Serialization and Deserialization dialog will be
displayed:
-
Select the type fields for which you want serialization/deserialization
code to be implemented for.
-
In the Serialization and/or deserialization section, specify the features
you want your type to be able to provide:
-
read:
check the Add deserialization constructor option.
-
write:
check the Add the GetObjectData serialization method option.
-
Generate XML comments: check this option if you want XML descriptive comments to be generated for the newly inserted code.
-
You can enclose the generated code between #Region
and #End Region directives
by checking the corresponding option.
-
Press the Standards button in order to review the naming standards configuration since this one will be considered when generating code.
-
Press Insert to generate and insert the desired code based on the above specified settings.
See Also
Back to top
|