eightHundreds
4/21/2017 - 5:24 AM

the T marked as [Serializable]

the T marked as [Serializable]

public static T DeepClone<T>(T obj)
{
 using (var ms = new MemoryStream())
 {
   var formatter = new BinaryFormatter();
   formatter.Serialize(ms, obj);
   ms.Position = 0;

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