提交.Net6版本
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
using Newtonsoft.Json;
|
||||
using System.Text;
|
||||
|
||||
namespace Yi.Framework.Common.Helper
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user