🍒 fix(Dict): 修复枚举校验异常问题
This commit is contained in:
parent
b9787194a9
commit
e849e9865f
@ -54,8 +54,7 @@ public class DictAttribute : ValidationAttribute, ITransient
|
||||
private async Task<ValidationResult> IsValidAsync(object? value, ValidationContext validationContext, CancellationToken cancellation)
|
||||
{
|
||||
// 1. 空值检查
|
||||
if (IsEmpty(value))
|
||||
return ValidationResult.Success;
|
||||
if (IsEmpty(value)) return ValidationResult.Success;
|
||||
|
||||
// 2. 获取属性类型
|
||||
var property = validationContext.ObjectType.GetProperty(validationContext.MemberName!);
|
||||
@ -81,7 +80,7 @@ public class DictAttribute : ValidationAttribute, ITransient
|
||||
// 6. 单选校验
|
||||
if (!Multiple)
|
||||
{
|
||||
var valStr = value?.ToString();
|
||||
var valStr = value!.GetType().IsEnum ? value.ToInt().ToString() : value.ToString();
|
||||
if (string.IsNullOrEmpty(valStr) || !dictHashSet.Contains(valStr))
|
||||
{
|
||||
return new ValidationResult($"提示:{ErrorMessage}|字典【{DictTypeCode}】不包含【{value}】!");
|
||||
@ -108,7 +107,7 @@ public class DictAttribute : ValidationAttribute, ITransient
|
||||
{
|
||||
foreach (var item in listValue)
|
||||
{
|
||||
var itemStr = item?.ToString();
|
||||
var itemStr = item.GetType().IsEnum ? item.ToInt().ToString() : item.ToString();
|
||||
if (string.IsNullOrEmpty(itemStr) || !dictHashSet.Contains(itemStr))
|
||||
{
|
||||
return new ValidationResult($"提示:{ErrorMessage}|字典【{DictTypeCode}】不包含【{item}】!");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user