Created
April 21, 2017 05:24
-
-
Save eightHundreds/102637d1209d060bb720ebb3fb83ce37 to your computer and use it in GitHub Desktop.
the T marked as [Serializable]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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