123456789101112131415161718192021222324252627 |
- using System;
- using System.ComponentModel.DataAnnotations;
- namespace GxPress.Common.Validation
- {
- [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)]
- public class MinAttribute : ValidationAttribute
- {
- private readonly int _min;
- public MinAttribute(int min)
- {
- _min = min;
- }
- public override bool IsValid(object value)
- {
- var min = (int)value;
- return min >= _min;
- }
- public override string FormatErrorMessage(string name)
- {
- return $"{name}必须大于{_min}";
- }
- }
- }
|