提交
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user