38 lines
956 B
C#
38 lines
956 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
|
|
namespace Appointment.Entity.ValidateAttribute
|
|
{
|
|
/// <summary>
|
|
/// 字符串最大长度
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Add:yuangb 2020-12-9
|
|
/// 使用格式:实体属性前加 [StringMaxLength(200, ErrorMessage = "备注说明最大长度200个字符")]
|
|
/// </remarks>
|
|
public class StringMaxLengthAttribute : ValidateAttribute
|
|
{
|
|
private int _MaxLength = 0;
|
|
|
|
/// <summary>
|
|
/// 报错提示
|
|
/// </summary>
|
|
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;
|
|
}
|
|
}
|
|
}
|