Skip to content

Commit

Permalink
[opt] 优化可空bean的流式格式,如果接下来的数据不为null|{}|<bean名>,则当作非空bean,直接读取后续数据
Browse files Browse the repository at this point in the history
  • Loading branch information
pirunxi committed Mar 25, 2024
1 parent c58d8e3 commit dd8f40f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,20 @@ public DType Accept(TBean type, ExcelStream x)
{
if (type.IsNullable)
{
string subType = x.Read().ToString().Trim();
if (subType == FieldNames.BeanNullType)
if (x.TryPeed(out object subTypeObj)) //ToString().Trim();
{
return null;
}
else if (subType != FieldNames.BeanNotNullType && subType != originBean.Name)
{
throw new Exception($"type:'{originBean.FullName}' 可空标识:'{subType}' 不合法(只能为{FieldNames.BeanNotNullType}{FieldNames.BeanNullType}{originBean.Name})");
string subType = subTypeObj.ToString().Trim();

if (subType == FieldNames.BeanNullType)
{
x.Read();
return null;
}
else if (subType == FieldNames.BeanNotNullType || subType == originBean.Name)
{
x.Read();
//throw new Exception($"type:'{originBean.FullName}' 可空标识:'{subType}' 不合法(只能为{FieldNames.BeanNotNullType}或{FieldNames.BeanNullType}或{originBean.Name})");
}
}
}
return new DBean(type, originBean, CreateBeanFields(originBean, x));
Expand Down
11 changes: 11 additions & 0 deletions src/Luban.DataLoader.Builtin/Excel/ExcelStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,17 @@ public bool TryRead(out object data)
return false;
}

public bool TryPeed(out object data)
{
int oldCurIndex = _curIndex;
if (TryRead(out data))
{
_curIndex = oldCurIndex;
return true;
}
return false;
}

public object Read(bool notSkip = false)
{
//if (curIndex <= toIndex)
Expand Down

0 comments on commit dd8f40f

Please sign in to comment.