| 12345678910111213141516171819202122232425262728293031 |
- using System;
- using System.ComponentModel.DataAnnotations;
- namespace Masuit.Tools.Core.Validator;
- /// <summary>
- /// 枚举值校验
- /// </summary>
- public class EnumOfAttribute : ValidationAttribute
- {
- private Type Type { get; set; }
- /// <summary>
- /// 枚举类型
- /// </summary>
- /// <param name="value"></param>
- public EnumOfAttribute(Type value)
- {
- Type = value;
- }
- public override bool IsValid(object value)
- {
- if (value is null)
- {
- return true;
- }
- return Enum.IsDefined(Type, value);
- }
- }
|