DeepClone

public static T DeepClone<T>(this T input) where T : ISerializable
{
   using (var stream = new MemoryStream())
   {
      var formatter = new BinaryFormatter();
      formatter.Serialize(stream, input);
      stream.Position = 0;
      return (T)formatter.Deserialize(stream);
   }
}
Example:
var stringbuilder = new StringBuilder("TestData");
var copy = stringbuilder.DeepClone();
Assert.IsFalse(Equals(stringbuilder,copy));

Description

It returns deep copy of the object.

Details

Double click on the code to select all.

 

;