// Deserializes the class from the config file. public virtual void Load() { // Declare the hashtable reference. // Open the file containing the data that you want to deserialize. FileStream fs = new FileStream(fileName, FileMode.Open); try { BinaryFormatter formatter = new BinaryFormatter(); // Deserialize the object from the file and // assign the reference to the local variable. PersistentBinary binObject = (PersistentBinary)formatter.Deserialize(fs); UpdateMemberVariables(binObject); } catch (SerializationException e) { Console.WriteLine("Failed to deserialize. Reason: " + e.Message); throw; } finally { fs.Close(); } }
// Internal methods ---------------------------------------------------- protected virtual void UpdateMemberVariables(PersistentBinary persistentBinary) { this.fileName = persistentBinary.fileName; }