SHARE
TWEET

Csharp Deep-Clone Object

ForeverZer0 Feb 11th, 2012 130 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public static object CloneObject(object obj)
  2. {
  3.     using (MemoryStream memStream = new MemoryStream())
  4.     {
  5.         BinaryFormatter binaryFormatter = new BinaryFormatter(null,
  6.              new StreamingContext(StreamingContextStates.Clone));
  7.         binaryFormatter.Serialize(memStream, obj);
  8.         memStream.Seek(0, SeekOrigin.Begin);
  9.         return binaryFormatter.Deserialize(memStream);
  10.     }
  11. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top