You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
965 B
C#

1 year ago
using Newtonsoft.Json;
using System.Text;
namespace Admin.Core.Common
{
public class SerializeHelper
{
/// <summary>
/// 序列化
/// </summary>
/// <param name="item"></param>
/// <returns></returns>
public static byte[] Serialize(object item)
{
var jsonString = JsonConvert.SerializeObject(item);
return Encoding.UTF8.GetBytes(jsonString);
}
/// <summary>
/// 反序列化
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <param name="value"></param>
/// <returns></returns>
public static TEntity Deserialize<TEntity>(byte[] value)
{
if (value == null)
{
return default(TEntity);
}
var jsonString = Encoding.UTF8.GetString(value);
return JsonConvert.DeserializeObject<TEntity>(jsonString);
}
}
}