1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- 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);
- }
- }
- /// <summary>
- /// 非空值校验
- /// </summary>
- public class NotNullOrEmptyAttribute : ValidationAttribute
- {
- public override bool IsValid(object value)
- {
- if (value is null)
- {
- return false;
- }
- return !value.IsNullOrEmpty();
- }
- }
|