|
|
@ -233,7 +233,6 @@ public class ClosedXmlExportImportService : IExportImportService |
|
|
|
if (property != null) |
|
|
|
{ |
|
|
|
var propertyType = property.PropertyType; |
|
|
|
|
|
|
|
if (value.ToString() != "") |
|
|
|
{ |
|
|
|
if (propertyType.IsEnum) |
|
|
@ -264,19 +263,22 @@ 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<RequiredAttribute>(); |
|
|
|
if (isHasRequiredAttribute == true) |
|
|
|
if (propertyType.IsEnum || propertyType.Name == nameof(Boolean) || propertyType.IsValueType) |
|
|
|
{ |
|
|
|
var requiredAttribute = property.GetCustomAttribute<RequiredAttribute>(); |
|
|
|
var displayName = property.GetCustomAttribute<DisplayAttribute>()?.Name ?? headerName; |
|
|
|
string errorMessage = string.Format(requiredAttribute.ErrorMessage, displayName); |
|
|
|
validationRresults.Add(new ValidationResult(errorMessage, new string[] { "错误" })); |
|
|
|
/* |
|
|
|
* 枚举、bool、值类型验证 Required 标注 |
|
|
|
* 框架中 Required 标注验证不为 NULL,非可空类型必填项无法通过框架方法验证 |
|
|
|
*/ |
|
|
|
var isHasRequiredAttribute = property.HasAttribute<RequiredAttribute>(); |
|
|
|
if (isHasRequiredAttribute == true) |
|
|
|
{ |
|
|
|
var requiredAttribute = property.GetCustomAttribute<RequiredAttribute>(); |
|
|
|
var displayName = property.GetCustomAttribute<DisplayAttribute>()?.Name ?? headerName; |
|
|
|
string errorMessage = string.Format(requiredAttribute.ErrorMessage, displayName); |
|
|
|
validationRresults.Add(new ValidationResult(errorMessage, new string[] { "错误" })); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|