Esempio n. 1
0
 public static T CloneViaBinaryData <T>(this T dataObjectToClone)
 {
     using (var dataStream = new MemoryStream())
     {
         var writer = new BinaryWriter(dataStream);
         BinaryDataExtensions.Save(dataObjectToClone, writer);
         dataStream.Seek(0, SeekOrigin.Begin);
         var reader       = new BinaryReader(dataStream);
         var clonedObject = (T)reader.Create();
         return(clonedObject);
     }
 }
Esempio n. 2
0
 public void SaveAndLoadRectangleManuallyWithBinaryWriterAndReader()
 {
     using (var dataStream = new MemoryStream())
     {
         var writer = new BinaryWriter(dataStream);
         var data   = Rectangle.One;
         BinaryDataExtensions.Save(data, writer);
         dataStream.Seek(0, SeekOrigin.Begin);
         var reader = new BinaryReader(dataStream);
         data = (Rectangle)reader.Create();
         Assert.AreEqual(Rectangle.One, data);
     }
 }
        public void CannotSaveObjectDataIfNull()
        {
            var binaryWriter = new BinaryWriter(new MemoryStream());

            Assert.Throws <ArgumentNullException>(() => BinaryDataExtensions.Save(null, binaryWriter));
        }