Last Updated: 12/2003
Note: There is a 3rd serializer, Soap, that is not discussed here. |
||||
using
System;
namespace
ConsoleApplication1 {
// Public default constructor as required by
XmlSerializer
class Class1 {
// Write items out to string
// Read items back in
// Show it worked |
Change the Item class to include the attributes in bold:
[XmlRootAttribute("Root")]
[XmlElement("GoodsDescription")]
[XmlAttribute("NumberInStock")]
[XmlIgnore]
// Public default constructor as required by
XmlSerializer
|
||||
using
System; // For Serializable attribute
namespace
ConsoleApplication1 {
class Class1 {
// Write items out to file
// Read items back in
// Show it worked |
To convert the example to use ISerializable, change the item class in the base example as follows: Change: Add the following methods to
the Item class body:
// Although optional, ISerializable doesn't make sense without this sort of
constructor No other changes to class1 are required. |