How to: Deserialize an Object • • 2 minutes to read • Contributors • • • • • In this article When you deserialize an object, the transport format determines whether you will create a stream or file object. After the transport format is determined, you can call the or methods, as required. To deserialize an object • Construct a using the type of the object to deserialize. • Call the method to produce a replica of the object. When deserializing, you must cast the returned object to the type of the original, as shown in the following example, which deserializes the object into a file (although it could also be deserialized into a stream). Dim myObject As MySerializableClass ' Construct an instance of the XmlSerializer with the type ' of object that is being deserialized. Dim mySerializer As XmlSerializer = New XmlSerializer(GetType(MySerializableClass)) ' To read the file, create a FileStream.
I have a base object which all my objects inherit from, and currently they can all save. (serialization) using RTTI. Supports both xml and binary and is extendable to any. And sorry huferry, I should have said it was standard delphi not.net.
Dim myFileStream As FileStream = _ New FileStream('myFileName.xml', FileMode.Open) ' Call the Deserialize method and cast to the object type. MyObject = CType( _ mySerializer.Deserialize(myFileStream), MySerializableClass) MySerializableClass myObject; // Construct an instance of the XmlSerializer with the type // of object that is being deserialized. XmlSerializer mySerializer = new XmlSerializer(typeof(MySerializableClass)); // To read the file, create a FileStream.

FileStream myFileStream = new FileStream('myFileName.xml', FileMode.Open); // Call the Deserialize method and cast to the object type. MyObject = (MySerializableClass) mySerializer.Deserialize(myFileStream) See also • • Feedback.