Skip to content

Instantly share code, notes, and snippets.

@eightHundreds
Created April 21, 2017 05:24
Show Gist options
  • Save eightHundreds/102637d1209d060bb720ebb3fb83ce37 to your computer and use it in GitHub Desktop.
Save eightHundreds/102637d1209d060bb720ebb3fb83ce37 to your computer and use it in GitHub Desktop.
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);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment