From c2ba79af419b25c463aae82fd3f70e7abfeffdf4 Mon Sep 17 00:00:00 2001 From: mahao Date: Fri, 7 Apr 2023 11:47:07 +0800 Subject: [PATCH] =?UTF-8?q?=E9=AA=8C=E8=AF=81=E5=BF=85=E5=A1=AB=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E6=B7=BB=E5=8A=A0=20IsNullableType=20=E5=88=A4?= =?UTF-8?q?=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ClosedXmlExportImportService.cs | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/be/Modules/Shared/src/Win_in.Sfs.Shared.Application/ExportAndImport/ClosedXmlExportImportService.cs b/be/Modules/Shared/src/Win_in.Sfs.Shared.Application/ExportAndImport/ClosedXmlExportImportService.cs index 13a6e3008..26fd511e7 100644 --- a/be/Modules/Shared/src/Win_in.Sfs.Shared.Application/ExportAndImport/ClosedXmlExportImportService.cs +++ b/be/Modules/Shared/src/Win_in.Sfs.Shared.Application/ExportAndImport/ClosedXmlExportImportService.cs @@ -233,7 +233,6 @@ public class ClosedXmlExportImportService : IExportImportService if (property != null) { var propertyType = property.PropertyType; - if (value.ToString() != "") { if (propertyType.IsEnum) @@ -264,22 +263,25 @@ public class ClosedXmlExportImportService : IExportImportService } else { - if (propertyType.IsEnum || propertyType.Name == nameof(Boolean) || propertyType.IsValueType) + if (propertyType.IsNullableType() == false) { - /* - * 枚举、bool、值类型验证 Required 标注 - * 框架中 Required 标注验证的是不为 NULL,非可空类型无法通过框架方法验证 - */ - var isHasRequiredAttribute = property.HasAttribute(); - if (isHasRequiredAttribute == true) + if (propertyType.IsEnum || propertyType.Name == nameof(Boolean) || propertyType.IsValueType) { - var requiredAttribute = property.GetCustomAttribute(); - var displayName = property.GetCustomAttribute()?.Name ?? headerName; - string errorMessage = string.Format(requiredAttribute.ErrorMessage, displayName); - validationRresults.Add(new ValidationResult(errorMessage, new string[] { "错误" })); + /* + * 枚举、bool、值类型验证 Required 标注 + * 框架中 Required 标注验证不为 NULL,非可空类型必填项无法通过框架方法验证 + */ + var isHasRequiredAttribute = property.HasAttribute(); + if (isHasRequiredAttribute == true) + { + var requiredAttribute = property.GetCustomAttribute(); + var displayName = property.GetCustomAttribute()?.Name ?? headerName; + string errorMessage = string.Format(requiredAttribute.ErrorMessage, displayName); + validationRresults.Add(new ValidationResult(errorMessage, new string[] { "错误" })); + } } } - } + } } } result.Add(model, validationRresults);