Created
June 30, 2021 18:57
-
-
Save pedrovasconcellos/87f4bb647f45679e534f891fb144626b to your computer and use it in GitHub Desktop.
Value copy
This file contains hidden or 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
| private static T DeepCopy<T>(T other) | |
| { | |
| using (MemoryStream ms = new MemoryStream()) | |
| { | |
| BinaryFormatter formatter = new BinaryFormatter(); | |
| formatter.Context = new StreamingContext(StreamingContextStates.Clone); | |
| formatter.Serialize(ms, other); | |
| 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