using System; using System.Collections.Generic; using System.Text; namespace Appointment.Entity.ValidateAttribute { /// /// 整型数值值范围效验 /// /// /// Add:yuangb 2019-3-11 /// 使用格式:实体属性前加[IntValue(minValue: 1000, maxValue: 999999, ErrorMessage = "验证码长度不正确")] /// public class LongValueAttribute : ValidateAttribute { /// /// 报错提示 /// public string ErrorMessage { get; set; } /// /// 最小值(包含) /// public long MinValue { get; private set; } /// /// 最大值(包含) /// public long MaxValue { get; private set; } /// /// /// /// 最小值(包含) /// 最大值(包含) public LongValueAttribute(long minValue, long maxValue) { this.MinValue = minValue; this.MaxValue = maxValue; } public override string Validate(object oValue) { if (oValue != null) { long lValue = Convert.ToInt64(oValue); if (lValue < MinValue || lValue > MaxValue) return ErrorMessage; } return null; } } }