1
This commit is contained in:
@@ -75,18 +75,20 @@ namespace BITKit
|
||||
if (netReaders.TryGetValue(typeName, out var netReader))
|
||||
return netReader.ReadBinaryAsObject(reader);
|
||||
var json = reader.ReadString();
|
||||
if (string.IsNullOrEmpty(json))
|
||||
{
|
||||
throw new Exception($"从二进制中读取的json值为空");
|
||||
}
|
||||
try
|
||||
{
|
||||
if (BITSharp.TryGetTypeFromFullName(typeName, out var type))
|
||||
return JsonConvert.DeserializeObject(json, type);
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception e)
|
||||
{
|
||||
BIT4Log.Warning<BITBinary>($"反序列化失败,类型:{typeName},值:\n{json}");
|
||||
throw;
|
||||
BIT4Log.LogException(e);
|
||||
}
|
||||
|
||||
|
||||
throw new Exception("未找到读取该二进制的BinaryReader");
|
||||
}
|
||||
|
||||
@@ -126,16 +128,8 @@ namespace BITKit
|
||||
{
|
||||
netReader.WriteBinaryAsObject(writer,value);
|
||||
}
|
||||
#if NET5_0_OR_GREATER
|
||||
else if( value is IBinarySerialize serialize)
|
||||
{
|
||||
serialize.Write(writer);
|
||||
}
|
||||
#endif
|
||||
else
|
||||
{
|
||||
//throw new Exception($"没有找到{value.GetType().Name}的Binary写入方法");
|
||||
writer.Write(value!.GetType().FullName!);
|
||||
writer.Write(JsonConvert.SerializeObject(value));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user