|
|
|
@ -85,6 +85,7 @@ namespace Apewer |
|
|
|
if (value == null) return new JValue(null, JTokenType.Null); |
|
|
|
if (value is Json json) return json?._jtoken ?? new JValue(null, JTokenType.Null); |
|
|
|
if (value is DateTime dt) return new JValue(SerializeDateTime(dt)); |
|
|
|
if (value is byte[] bytes) return new JValue(SerializeBytes(bytes)); |
|
|
|
|
|
|
|
if (value is string) return new JValue(value); |
|
|
|
if (value is bool) return new JValue(value); |
|
|
|
@ -1290,6 +1291,7 @@ namespace Apewer |
|
|
|
|
|
|
|
if (value == null) { json.AddItem(); } |
|
|
|
else if (value is DateTime dt) { json.AddItem(SerializeDateTime(dt)); } |
|
|
|
else if (value is byte[] bytes) { json.AddItem(SerializeBytes(bytes)); } |
|
|
|
else if (value is bool) { json.AddItem((bool)value); } |
|
|
|
else if (value is byte) { json.AddItem((byte)value); } |
|
|
|
else if (value is sbyte) { json.AddItem((sbyte)value); } |
|
|
|
@ -1401,6 +1403,7 @@ namespace Apewer |
|
|
|
|
|
|
|
if (value == null) { json.SetProperty(field); } |
|
|
|
else if (value is DateTime dt) { json.SetProperty(field, SerializeDateTime(dt)); } |
|
|
|
else if (value is byte[] bytes) { json.SetProperty(field, SerializeBytes(bytes)); } |
|
|
|
else if (value is bool) { json.SetProperty(field, (bool)value); } |
|
|
|
else if (value is byte) { json.SetProperty(field, (byte)value); } |
|
|
|
else if (value is sbyte) { json.SetProperty(field, (sbyte)value); } |
|
|
|
@ -1959,6 +1962,7 @@ namespace Apewer |
|
|
|
else if (pt.Equals(typeof(float))) setter.Invoke(entity, new object[] { Float(value) }); |
|
|
|
else if (pt.Equals(typeof(double))) setter.Invoke(entity, new object[] { Double(value) }); |
|
|
|
else if (pt.Equals(typeof(decimal))) setter.Invoke(entity, new object[] { Decimal(value) }); |
|
|
|
else if (pt.Equals(typeof(byte[]))) setter.Invoke(entity, new object[] { DeserializeBytes(value) }); |
|
|
|
else |
|
|
|
{ |
|
|
|
var serializable = (force || _forceall); |
|
|
|
@ -2539,6 +2543,47 @@ namespace Apewer |
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Byte[]
|
|
|
|
|
|
|
|
static Func<byte[], string> _bytes_serializer = null; |
|
|
|
static Func<object, byte[]> _bytes_deserializer = null; |
|
|
|
|
|
|
|
/// <summary>自定义 Byte[] 序列化程序。</summary>
|
|
|
|
public static Func<byte[], string> BytesSerializer { get => _bytes_serializer; set => _bytes_serializer = value; } |
|
|
|
|
|
|
|
/// <summary>自定义 Byte[] 反序列化程序。</summary>
|
|
|
|
public static Func<object, byte[]> BytesDeserializer { get => _bytes_deserializer; set => _bytes_deserializer = value; } |
|
|
|
|
|
|
|
/// <summary>序列化 Byte[] 实例。</summary>
|
|
|
|
public static string SerializeBytes(byte[] bytes) |
|
|
|
{ |
|
|
|
var serializer = _bytes_serializer; |
|
|
|
if (serializer != null) return serializer.Invoke(bytes); |
|
|
|
|
|
|
|
if (bytes == null) return null; |
|
|
|
return Convert.ToBase64String(bytes); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>反序列化 Byte[] 实例。</summary>
|
|
|
|
public static byte[] DeserializeBytes(object value) |
|
|
|
{ |
|
|
|
var deserializer = _bytes_deserializer; |
|
|
|
if (deserializer != null) return deserializer.Invoke(value); |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
if (value is byte[] bytes) return bytes; |
|
|
|
if (value is string base64) return Convert.FromBase64String(base64); |
|
|
|
return null; |
|
|
|
} |
|
|
|
catch |
|
|
|
{ |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region DateTime
|
|
|
|
|
|
|
|
static Func<DateTime, string> _datetime_serializer = null; |
|
|
|
@ -2559,7 +2604,7 @@ namespace Apewer |
|
|
|
return ClockUtility.Lucid(dateTime); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>序列化 DateTime 实例。</summary>
|
|
|
|
/// <summary>反序列化 DateTime 实例。</summary>
|
|
|
|
public static DateTime DeserializeDateTime(object value) |
|
|
|
{ |
|
|
|
var deserializer = _datetime_deserializer; |
|
|
|
|