using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; namespace LMS.Common.Attributes { [AttributeUsage(AttributeTargets.Property)] public class NotEmptyAttribute : ValidationAttribute { protected override ValidationResult IsValid(object value, ValidationContext validationContext) { if (value is string str && string.IsNullOrWhiteSpace(str)) { return new ValidationResult(ErrorMessage ?? "字段不能为空"); } return ValidationResult.Success; } } }