Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to implement a (deep) cloning method in .NET within my library information system.
Why is BinaryFormatter not being recognized?
C#
using System.IO;
using System.Runtime.Serialization.Formatters;
public static Audit DeepClone<T>(Audit obj)
   {
       using (var ms = new MemoryStream())
       {
           var formatter = new BinaryFormatter();
           formatter.Serialize(ms, obj);
           ms.Position = 0;

           return (Audit)formatter.Deserialize(ms);
       }
   }

I am using Visual Studio 2010/.NET 4.5.

References:
1. Spec at http://www.scribd.com/doc/178540653/Software-Engineering-Project-IS3139-A-School-Library-v2?secret_password=127olku950mzko3glvep[^]
2. Code snippet sourced from http://stackoverflow.com/questions/129389/how-do-you-do-a-deep-copy-an-object-in-net-c-specifically[^]
3. BinaryFormatter Class documentation at http://msdn.microsoft.com/en-us/library/system.runtime.serialization.formatters.binary.binaryformatter(v=vs.110).aspx[^]
Posted
Updated 17-Nov-13 22:08pm
v2

1 solution

Sample code in the Binary Formatter documentation page[^] features the following line:
C#
using System.Runtime.Serialization.Formatters.Binary;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900