From 8e4ef0952dc19f8034c4239051acaafd8a0fc2ba Mon Sep 17 00:00:00 2001 From: walon Date: Wed, 22 Dec 2021 15:04:28 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E5=A4=8D=E3=80=91=E4=BF=AE?= =?UTF-8?q?=E5=A4=8Dexcel=E4=B8=AD=E6=9C=AA=E5=AE=9A=E4=B9=89=E5=A4=9A?= =?UTF-8?q?=E6=80=81=E6=88=96=E5=8F=AF=E7=A9=BA=E7=B1=BB=E5=9E=8B=E7=9A=84?= =?UTF-8?q?=5F=5Ftype=5F=5F=E5=88=97=E6=97=B6=E6=8A=9B=E5=87=BA=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E5=87=86=E7=A1=AE=E5=AE=9A=E4=BD=8D=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E7=9A=84=E5=BC=82=E5=B8=B8=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Source/DataCreators/SheetDataCreator.cs | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/Luban.Job.Cfg/Source/DataCreators/SheetDataCreator.cs b/src/Luban.Job.Cfg/Source/DataCreators/SheetDataCreator.cs index a1cb50f..91fb51f 100644 --- a/src/Luban.Job.Cfg/Source/DataCreators/SheetDataCreator.cs +++ b/src/Luban.Job.Cfg/Source/DataCreators/SheetDataCreator.cs @@ -394,12 +394,18 @@ namespace Luban.Job.Cfg.DataCreators var originBean = (DefBean)type.Bean; if (originBean.IsAbstractType) { - string subType = row.GetSubTitleNamedRow(DefBean.TYPE_NAME_KEY).Current.ToString().Trim(); - if (subType.ToLower() == DefBean.BEAN_NULL_STR) + TitleRow typeTitle = row.GetSubTitleNamedRow(DefBean.TYPE_NAME_KEY); + if (typeTitle == null) + { + throw new Exception($"type:'{originBean.FullName}' 是多态类型,需要定义'{DefBean.TYPE_NAME_KEY}'列来指定具体子类型"); + } + + string subType = typeTitle.Current?.ToString()?.Trim(); + if (subType == null || subType == DefBean.BEAN_NULL_STR) { if (!type.IsNullable) { - throw new Exception($"type:'{type}' 不是可空类型 '{type.Bean.FullName}?' , 不能为空"); + throw new Exception($"type:'{originBean.FullName}' 不是可空类型 '{type.Bean.FullName}?' , 不能为空"); } return null; } @@ -407,7 +413,7 @@ namespace Luban.Job.Cfg.DataCreators DefBean implType = (DefBean)originBean.GetNotAbstractChildType(subType); if (implType == null) { - throw new Exception($"type:'{fullType}' 不是 bean 类型"); + throw new Exception($"type:'{fullType}' 不是 bean 类型或者不是'{originBean.FullName}'的子类"); } return new DBean(type, implType, CreateBeanFields(implType, sheet, row)); } @@ -415,14 +421,19 @@ namespace Luban.Job.Cfg.DataCreators { if (type.IsNullable) { - string subType = row.GetSubTitleNamedRow(DefBean.TYPE_NAME_KEY).Current?.ToString()?.Trim(); + TitleRow typeTitle = row.GetSubTitleNamedRow(DefBean.TYPE_NAME_KEY); + if (typeTitle == null) + { + throw new Exception($"type:'{originBean.FullName}' 是可空类型,需要定义'{DefBean.TYPE_NAME_KEY}'列来指明是否可空"); + } + string subType = typeTitle.Current?.ToString()?.Trim(); if (subType == null || subType == DefBean.BEAN_NULL_STR) { return null; } else if (subType != DefBean.BEAN_NOT_NULL_STR && subType != originBean.Name) { - throw new Exception($"type:'{type.Bean.FullName}' 可空标识:'{subType}' 不合法(只能为{DefBean.BEAN_NOT_NULL_STR}或{DefBean.BEAN_NULL_STR}或{originBean.Name})"); + throw new Exception($"type:'{originBean.FullName}' 可空标识:'{subType}' 不合法(只能为'{DefBean.BEAN_NULL_STR}'或'{DefBean.BEAN_NOT_NULL_STR}'或'{originBean.Name}')"); } }