Mega Code Archive

 
Categories / C# / File Stream
 

Deep Copy with MemoryStream

//http://simpledbbrowser.codeplex.com/ //License:  Microsoft Public License (Ms-PL)   using System.Diagnostics; using System.IO; using System.Runtime.Serialization.Formatters.Binary; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; namespace AWS.Framework.WPF.Utility {     public sealed class Helpers     {         public static T DeepCopy<T>(object toClone)         {             using (MemoryStream ms = new MemoryStream())             {                 BinaryFormatter bf = new BinaryFormatter();                 bf.Serialize(ms, toClone);                 ms.Position = 0;                 return (T)bf.Deserialize(ms);             }         }    } }