33 lines
762 B
C#
33 lines
762 B
C#
#region
|
|
|
|
using System.Text;
|
|
using System.Text.Json;
|
|
|
|
#endregion
|
|
|
|
namespace Web.Core.Common.Helper;
|
|
|
|
public class SerializeHelper
|
|
{
|
|
/// <summary>
|
|
/// 序列化
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <returns></returns>
|
|
public static byte[] Serialize(object item)
|
|
{
|
|
return item == null ? null : JsonSerializer.SerializeToUtf8Bytes(item);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 反序列化
|
|
/// </summary>
|
|
/// <typeparam name="TEntity"></typeparam>
|
|
/// <param name="value"></param>
|
|
/// <returns></returns>
|
|
public static T Deserialize<T>(byte[] value)
|
|
{
|
|
var jsonString = Encoding.UTF8.GetString(value);
|
|
return value == null ? default : JsonSerializer.Deserialize<T>(value);
|
|
}
|
|
} |