Dotfuscator User's Guide
Running the Serialization Sample

The serialization sample can be run by executing the Serialization.exe assembly produced by the make.bat command. The application has two modes of operation controlled by command line parameters. The “-s” option, causes the application to instantiate an object of type “Tester”, and persist it to the file “Sum.out”. Each Tester object has 3 integer fields that make up the persisted data. The following code from the Tester class is used to persist the object:

Tester Class Code
Copy Code
   // create a file stream to write the file
   FileStream stream = new fileStream("Sum.out",FileMode.Create);
  
   BinaryFormatter formatter = new BinaryFormatter();
   // serialize to disk
   formatter.Serialize(stream,this);
   stream.Close();

The “-d” option, causes the application to de-serialize an object that had previously been persisted in the file “Sum.out”. The following code is responsible for doing the de-serialization:

De-Serialization Code
Copy Code
   stream = new FileStream("Sum.out",FileMode.Open);
   BinaryFormatter formatter = new BinaryFormatter();
   return (Tester) formatter.Deserialize(stream);

 

 


© 2016 PreEmptive Solutions, LLC. All Rights Reserved.

www.preemptive.com