namespace Dpz.Core.WebApi;
/// <summary>
/// 数组model验证
/// </summary>
public class MustHaveOneElementOfStringAttribute : ValidationAttribute
{
/// <summary>
/// 验证
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public override bool IsValid(object? value)
{
if (value is null)
{
return true;
}
if (value is not IEnumerable<string> collection)
{
return false;
}
var array = collection.ToArray();
if (array.Length == 0)
{
return true;
}
return array.All(x => !string.IsNullOrEmpty(x));
}
}
AI 正在分析代码…
评论加载中...