Deep Copy with MemoryStream : Memory Stream « File Stream « C# / C Sharp






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);
            }
        }
   }
}

   
    
    
  








Related examples in the same category

1.Create a MemoryStream
2.MemoryStream.Write
3.Use MemoryStream and BinaryWriter to convert decimal to byte arrayUse MemoryStream and BinaryWriter to convert decimal to byte array
4.Use MemoryStream and BinaryReader to convert Byte array to decimalUse MemoryStream and BinaryReader to convert Byte array to decimal
5.MemoryStream.ToArray, MemoryStream.ReadDecimal
6.Memory-Mapped Files
7.Deep clone with MemoryStream
8.Using MemoryStream to Serialize and Desirialize
9.Convert a string into an array of bytes