mirror of
https://github.com/babalae/better-genshin-impact
synced 2025-01-08 11:57:53 +08:00
37 lines
963 B
C#
37 lines
963 B
C#
using System;
|
|
using System.IO;
|
|
using System.Runtime.Serialization.Formatters.Binary;
|
|
|
|
namespace BetterGenshinImpact.Helpers;
|
|
|
|
public class ObjectUtils
|
|
{
|
|
[Obsolete("Obsolete")]
|
|
public static byte[] Serialize(object obj)
|
|
{
|
|
var ms = new MemoryStream();
|
|
var formatter = new BinaryFormatter();
|
|
#pragma warning disable SYSLIB0011
|
|
formatter.Serialize(ms, obj);
|
|
#pragma warning restore SYSLIB0011
|
|
byte[] bytes = ms.GetBuffer();
|
|
return bytes;
|
|
}
|
|
|
|
[Obsolete("Obsolete")]
|
|
public static object Deserialize(byte[] bytes)
|
|
{
|
|
//利用传来的byte[]创建一个内存流
|
|
var ms = new MemoryStream(bytes)
|
|
{
|
|
Position = 0
|
|
};
|
|
var formatter = new BinaryFormatter();
|
|
#pragma warning disable SYSLIB0011
|
|
var obj = formatter.Deserialize(ms); //把内存流反序列成对象
|
|
#pragma warning restore SYSLIB0011
|
|
ms.Close();
|
|
return obj;
|
|
}
|
|
}
|