using System.ComponentModel.DataAnnotations; namespace Sai.Toolkit.Mvvm.Attributes; [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("输入内容不是数值。"); } }