1
This commit is contained in:
@@ -8,13 +8,11 @@ using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Web;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
|
||||
|
||||
namespace iMES.Core.Extensions
|
||||
{
|
||||
|
||||
@@ -543,23 +541,28 @@ namespace iMES.Core.Extensions
|
||||
return info;
|
||||
}
|
||||
|
||||
public static T FromBytes<T>(this byte[] data)
|
||||
public static byte[] ToBytes(this object obj)
|
||||
{
|
||||
if (data == null || data.Length == 0)
|
||||
if (obj == null)
|
||||
return null;
|
||||
var bf = new BinaryFormatter();
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
return default(T);
|
||||
bf.Serialize(ms, obj);
|
||||
return ms.ToArray();
|
||||
}
|
||||
return JsonSerializer.Deserialize<T>(data);
|
||||
}
|
||||
|
||||
public static T ToObject<T>(this byte[] source)
|
||||
public static object ToObject(this byte[] source)
|
||||
{
|
||||
if (source == null || source.Length == 0)
|
||||
using (var memStream = new MemoryStream())
|
||||
{
|
||||
return default(T);
|
||||
var bf = new BinaryFormatter();
|
||||
memStream.Write(source, 0, source.Length);
|
||||
memStream.Seek(0, SeekOrigin.Begin);
|
||||
var obj = bf.Deserialize(memStream);
|
||||
return obj;
|
||||
}
|
||||
|
||||
return JsonSerializer.Deserialize<T>(source);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user