mirror of
https://github.com/FriendshipIsEpic/FiE-Game.git
synced 2024-11-23 22:27:58 +01:00
22 lines
499 B
C#
22 lines
499 B
C#
|
using System.IO;
|
||
|
using System.Runtime.Serialization.Formatters.Binary;
|
||
|
|
||
|
namespace Fie.Utility
|
||
|
{
|
||
|
public static class FieDeepClone
|
||
|
{
|
||
|
public static T CloneDeep<T>(this T target)
|
||
|
{
|
||
|
object obj = null;
|
||
|
using (MemoryStream memoryStream = new MemoryStream())
|
||
|
{
|
||
|
BinaryFormatter binaryFormatter = new BinaryFormatter();
|
||
|
binaryFormatter.Serialize(memoryStream, target);
|
||
|
memoryStream.Position = 0L;
|
||
|
obj = binaryFormatter.Deserialize(memoryStream);
|
||
|
}
|
||
|
return (T)obj;
|
||
|
}
|
||
|
}
|
||
|
}
|