From dd8f40f4b8c2f1f412b71758839cdb017058ae26 Mon Sep 17 00:00:00 2001 From: walon Date: Mon, 25 Mar 2024 22:30:47 +0800 Subject: [PATCH] =?UTF-8?q?[opt]=20=E4=BC=98=E5=8C=96=E5=8F=AF=E7=A9=BAbea?= =?UTF-8?q?n=E7=9A=84=E6=B5=81=E5=BC=8F=E6=A0=BC=E5=BC=8F=EF=BC=8C?= =?UTF-8?q?=E5=A6=82=E6=9E=9C=E6=8E=A5=E4=B8=8B=E6=9D=A5=E7=9A=84=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E4=B8=8D=E4=B8=BAnull|{}|=EF=BC=8C?= =?UTF-8?q?=E5=88=99=E5=BD=93=E4=BD=9C=E9=9D=9E=E7=A9=BAbean=EF=BC=8C?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E8=AF=BB=E5=8F=96=E5=90=8E=E7=BB=AD=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DataVisitors/ExcelStreamDataCreator.cs | 20 ++++++++++++------- .../Excel/ExcelStream.cs | 11 ++++++++++ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/Luban.DataLoader.Builtin/DataVisitors/ExcelStreamDataCreator.cs b/src/Luban.DataLoader.Builtin/DataVisitors/ExcelStreamDataCreator.cs index 76822980..6aeb92bf 100644 --- a/src/Luban.DataLoader.Builtin/DataVisitors/ExcelStreamDataCreator.cs +++ b/src/Luban.DataLoader.Builtin/DataVisitors/ExcelStreamDataCreator.cs @@ -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)); diff --git a/src/Luban.DataLoader.Builtin/Excel/ExcelStream.cs b/src/Luban.DataLoader.Builtin/Excel/ExcelStream.cs index 48f4d92e..d2a9f399 100644 --- a/src/Luban.DataLoader.Builtin/Excel/ExcelStream.cs +++ b/src/Luban.DataLoader.Builtin/Excel/ExcelStream.cs @@ -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)