using System; using System.Collections.Generic; using System.Text; namespace Appointment.Entity.ValidateAttribute { /// /// 字符串最大长度 /// /// /// Add:yuangb 2020-12-9 /// 使用格式:实体属性前加 [StringMaxLength(200, ErrorMessage = "备注说明最大长度200个字符")] /// public class StringMaxLengthAttribute : ValidateAttribute { private int _MaxLength = 0; /// /// 报错提示 /// public string ErrorMessage { get; set; } public StringMaxLengthAttribute(int maxLength) { _MaxLength = maxLength; } public override string Validate(object oValue) { if (oValue != null && oValue.ToString().Length > _MaxLength) { return ErrorMessage; } return null; } } }