Files
ShrlAlgoToolkit/ShrlAlgo.Toolkit.Mvvm/Attributes/NotNullOrEmptyAttribute.cs

14 lines
541 B
C#
Raw Normal View History

2024-09-22 11:05:41 +08:00
using System.ComponentModel.DataAnnotations;
namespace ShrlAlgo.Toolkit.Mvvm.Attributes;
2024-09-22 11:05:41 +08:00
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter)]
public sealed class NotNullOrEmptyAttribute : ValidationAttribute
{
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
var b = value != null || (value is string str && !string.IsNullOrEmpty(str));
return b ? ValidationResult.Success : new("输入内容不是数值。");
}
}