Skip to content

Commit

Permalink
支持可空类型,遇到无数据时返回null
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Apr 19, 2024
1 parent 720da82 commit 4b6dc22
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions NewLife.Redis/RedisEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,15 @@ public virtual Packet Encode(Object value)
if (type == typeof(Byte[])) return pk.ReadBytes();
if (type.As<IAccessor>()) return type.AccessorRead(pk);

// 支持可空类型,遇到无数据时返回null
var ntype = Nullable.GetUnderlyingType(type);
if (pk.Total == 0 && ntype != null && ntype != type) return null;
if (ntype != null) type = ntype;

//var str = pk.ToStr().Trim('\"');
var str = pk.ToStr();
if (type.GetTypeCode() == TypeCode.String) return str;

// 支持可空类型
type = Nullable.GetUnderlyingType(type) ?? type;
//if (type.GetTypeCode() != TypeCode.Object) return str.ChangeType(type);
if (type.GetTypeCode() != TypeCode.Object)
{
Expand Down

0 comments on commit 4b6dc22

Please sign in to comment.