Files
AppointmentOA/api_v1/Appointment.Entity/ValidateAttribute/LongValueAttribute.cs
2022-07-24 14:48:54 +08:00

53 lines
1.4 KiB
C#

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