To read a class object from an XML file, you can use serialization and deserialization. The following code shows an example of how to do this:
main.cs1022 chars41 linesIn the SerializeToXml method, an instance of the XmlSerializer class is created with the type of the MyClass class. The method then uses a TextWriter to write the serialized object to a file.
In the DeserializeFromXml method, an instance of the XmlSerializer class is again created with the type of the MyClass class. The method then uses a TextReader to read the serialized object from the file and deserialize it.
Note that the MyClass class is marked with the [Serializable] attribute, which makes it possible to serialize and deserialize instances of the class.
gistlibby LogSnag