コード例 #1
0
        // 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();
            }
        }
コード例 #2
0
 // Internal methods ----------------------------------------------------
 protected virtual void UpdateMemberVariables(PersistentBinary persistentBinary)
 {
     this.fileName = persistentBinary.fileName;
 }