using System; using System.ComponentModel.DataAnnotations; namespace Util.Validation.Tests.Samples; /// /// 验证样例 /// public class Sample : IValidation{ /// /// 验证必填项 /// [Required( ErrorMessage = "Required" )] public string RequiredValue { get; set; } /// /// 验证字符串长度 /// [StringLength(3, ErrorMessage = "StringLength" )] public string StringLengthValue { get; set; } /// /// 验证 /// public ValidationResultCollection Validate() { var result = DataAnnotationValidation.Validate( this ); if( result.IsValid ) return ValidationResultCollection.Success; throw new ArgumentException(); } }