using System.ComponentModel.DataAnnotations; 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; } } }