public void SerializationWithoutSurrogate()
        {
            FileStream       stream     = new FileStream("Prova.bin", System.IO.FileMode.Create);
            CompactFormatter CFormatter = new CompactFormatter();

            Console.WriteLine(CFormatter.Mode);
            SimpleObjectSurrogate obj = new SimpleObjectSurrogate(42, "BELLA RAGA", 3.1415);

            try
            {
                CFormatter.Serialize(stream, obj);
            }
            catch (System.Exception err)
            {
                stream.Close();
                throw err;
            }

            stream.Flush();
            stream.Close();

            stream = new FileStream("Prova.bin", System.IO.FileMode.Open);
            CompactFormatter CFormatter2 = new CompactFormatter();

            SimpleObjectSurrogate obj2;

            obj2 = (SimpleObjectSurrogate)CFormatter2.Deserialize(stream);
            Console.WriteLine(obj.Real);

            stream.Close();

            Assert.AreEqual(obj, obj2);
        }
        public void SerializationWithSurrogate()
        {
            FileStream       stream     = new FileStream("Prova.bin", System.IO.FileMode.Create);
            CompactFormatter CFormatter = new CompactFormatter();

            CFormatter.AddSurrogate(typeof(Surrogate.DefaultSurrogates));

            SimpleObjectSurrogate obj = new SimpleObjectSurrogate(42, "BELLA RAGA", 3.1415);

            CFormatter.Serialize(stream, obj);
            stream.Flush();
            stream.Close();

            stream = new FileStream("Prova.bin", System.IO.FileMode.Open);
            CompactFormatter CFormatter2 = new CompactFormatter();

            CFormatter2.AddSurrogate(typeof(Surrogate.DefaultSurrogates));

            SimpleObjectSurrogate obj2;

            obj2 = (SimpleObjectSurrogate)CFormatter2.Deserialize(stream);
            Console.WriteLine(obj.Real);

            stream.Close();

            Assert.AreEqual(obj, obj2);
        }
 public override bool Equals(object obj)
 {
     if (!obj.GetType().Equals(typeof(SimpleObjectSurrogate)))
     {
         return(false);
     }
     else
     {
         SimpleObjectSurrogate answer = (SimpleObjectSurrogate)obj;
         return(answer.number == number && answer.real == real &&
                answer.text == text);
     }
 }