Exemplo n.º 1
0
 /// <summary>
 /// Invoke
 /// </summary>
 /// <param name="context"></param>
 /// <param name="next"></param>
 /// <returns></returns>
 /// <exception cref="ArgumentInvalidException"></exception>
 public override Task Invoke(ParameterAspectContext context, ParameterAspectDelegate next)
 {
     AssertionJudgment.Require2Validation <ArgumentInvalidException>(
         context.Parameter.Type.Is(TypeClass.StringClass),
         Message, context.Parameter.Name);
     return(next(context));
 }
Exemplo n.º 2
0
        /// <summary>
        /// Invoke
        /// </summary>
        /// <param name="context"></param>
        /// <param name="next"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentInvalidException"></exception>
        public override Task Invoke(ParameterAspectContext context, ParameterAspectDelegate next)
        {
            var condition = MayBeNullable
                ? context.Parameter.IsNot(TypeClass.IntClass).OrNot(TypeClass.IntNullableClass)
                : context.Parameter.Type.IsNot(TypeClass.IntClass);

            AssertionJudgment.Require2Validation <ArgumentInvalidException>(condition,
                                                                            Message, context.Parameter.Name);
            return(next(context));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Invoke
        /// </summary>
        /// <param name="context"></param>
        /// <param name="next"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentInvalidException"></exception>
        public override Task Invoke(ParameterAspectContext context, ParameterAspectDelegate next)
        {
            var condition = MayBeNullable
                ? TypeJudgment.IsNumericType(context.Parameter.Type)
                : TypeJudgment.IsNumericType(context.Parameter.Type) && !TypeJudgment.IsNullableType(context.Parameter.Type);

            AssertionJudgment.Require2Validation <ArgumentInvalidException>(condition,
                                                                            Message, context.Parameter.Name);
            return(next(context));
        }
Exemplo n.º 4
0
 /// <summary>
 /// 检查字符串是否为 null、String.Empty 或 Blank
 /// </summary>
 /// <param name="argument"></param>
 /// <param name="argumentName"></param>
 /// <param name="message"></param>
 public static void CheckNull(this string argument, string argumentName, string message = null)
 {
     AssertionJudgment.Require2 <ArgumentNullException>(
         !string.IsNullOrWhiteSpace(argument),
         argumentName, $"{nameof(argument)} can not be null or white space.");
 }
 /// <summary>
 /// 检查时间是否为未来
 /// <para>如果是未来,则抛出异常</para>
 /// </summary>
 /// <param name="argument"></param>
 /// <param name="argumentName"></param>
 /// <param name="message"></param>
 /// <exception cref="ArgumentOutOfRangeException"></exception>
 public static void IsNotInFuture(DateTime argument, string argumentName, string message = null)
 {
     AssertionJudgment.Require2Validation <ArgumentOutOfRangeException>(
         argument <= DateTime.UtcNow,
         argumentName, argument, message ?? $"{nameof(argument)} can not be in future.");
 }
 /// <summary>
 /// 检查时间是否合法
 /// </summary>
 /// <param name="argument"></param>
 /// <param name="argumentName"></param>
 /// <param name="message"></param>
 /// <exception cref="ArgumentOutOfRangeException"></exception>
 public static void IsNotInvalidDate(DateTime argument, string argumentName, string message = null)
 {
     AssertionJudgment.Require2Validation <ArgumentInvalidException>(
         DateTimeJudgment.IsValid(argument),
         message ?? $"{nameof(argument)} is invalid datetime value.", argumentName);
 }
 /// <summary>
 /// 检查时间间隔是否为非正数
 /// </summary>
 /// <param name="argument"></param>
 /// <param name="argumentName"></param>
 /// <param name="message"></param>
 /// <exception cref="ArgumentOutOfRangeException"></exception>
 public static void IsNotNegativeOrZero(TimeSpan argument, string argumentName, string message = null)
 {
     AssertionJudgment.Require2Validation <ArgumentOutOfRangeException>(
         argument > TimeSpan.Zero,
         argumentName, argument, message ?? $"{nameof(argument)} can not be negative or zero.");
 }
Exemplo n.º 8
0
 /// <summary>
 /// 检查字符串是否为 Blank
 /// </summary>
 /// <param name="argument"></param>
 /// <param name="argumentName"></param>
 /// <param name="message"></param>
 public static void IsNotEmpty(string argument, string argumentName, string message = null)
 {
     AssertionJudgment.Require2Validation <ArgumentNullException>(
         !string.IsNullOrWhiteSpace((argument ?? string.Empty).Trim()),
         argumentName, message ?? $"{nameof(argument)} can not be blank.");
 }
Exemplo n.º 9
0
 /// <summary>
 /// 检查 Guid 是否为空
 /// </summary>
 /// <param name="argument"></param>
 /// <param name="argumentName"></param>
 /// <param name="message"></param>
 public static void IsNotEmpty(Guid argument, string argumentName, string message = null)
 {
     AssertionJudgment.Require2Validation <ArgumentNullException>(
         !GuidJudgment.IsNullOrEmpty(argument),
         argumentName, message ?? $"{nameof(argument)} can not be null or empty.");
 }
Exemplo n.º 10
0
 /// <summary>
 /// 检查集合至少包含多少个元素
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="argument"></param>
 /// <param name="argumentName"></param>
 /// <param name="number"></param>
 /// <param name="message"></param>
 public static void IsAtLeast <T>(ICollection <T> argument, string argumentName, int number, string message = null)
 {
     AssertionJudgment.Require2Validation <ArgumentOutOfRangeException>(
         CollectionJudgment.ContainsAtLeast(argument, number),
         argumentName, argument.Count, message ?? $"{nameof(argument)} should has {number} items at least.");
 }
Exemplo n.º 11
0
 /// <summary>
 /// 检查集合是否为空
 /// </summary>
 /// <param name="argument"></param>
 /// <param name="argumentName"></param>
 /// <param name="message"></param>
 public static void IsNotNull(IEnumerable argument, string argumentName, string message = null)
 {
     AssertionJudgment.Require2Validation <ArgumentNullException>(
         !CollectionJudgment.IsNull(argument),
         argumentName, message ?? $"{nameof(argument)} can not be null.");
 }
Exemplo n.º 12
0
 /// <summary>
 /// 检查对象是否为空
 /// </summary>
 /// <param name="argument"></param>
 /// <param name="argumentName"></param>
 /// <param name="message"></param>
 public static void IsNotNull(object argument, string argumentName, string message = null)
 {
     AssertionJudgment.Require2Validation <ArgumentNullException>(
         argument != null,
         argumentName, message ?? $"{nameof(argument)} can not be null.");
 }
Exemplo n.º 13
0
 /// <summary>
 /// 检查字符串长度是否超界
 /// </summary>
 /// <param name="argument"></param>
 /// <param name="length"></param>
 /// <param name="argumentName"></param>
 /// <param name="message"></param>
 public static void IsNotOutOfLength(string argument, int length, string argumentName, string message = null)
 {
     AssertionJudgment.Require2Validation <ArgumentOutOfRangeException>(
         argument.Trim().Length <= length,
         argumentName, argument.Trim().Length, message ?? $"{nameof(argument)}'s length can not be greater than {length}.");
 }
Exemplo n.º 14
0
 /// <summary>
 /// 检查键值对是否为空
 /// </summary>
 /// <typeparam name="TKey"></typeparam>
 /// <typeparam name="TValue"></typeparam>
 /// <param name="argument"></param>
 /// <param name="argumentName"></param>
 /// <param name="message"></param>
 public static void CheckNull <TKey, TValue>(this KeyValuePair <TKey, TValue> argument, string argumentName, string message = null)
 {
     AssertionJudgment.Require2 <ArgumentNullException>(
         !string.IsNullOrWhiteSpace(argument.ToString()),
         argumentName, message ?? $"{nameof(argument)} contains nothing.");
 }
Exemplo n.º 15
0
 /// <summary>
 /// 检查长整数是否为负数
 /// </summary>
 /// <param name="argument"></param>
 /// <param name="argumentName"></param>
 /// <param name="message"></param>
 public static void IsNotNegative(long argument, string argumentName, string message = null)
 {
     AssertionJudgment.Require2 <ArgumentOutOfRangeException>(
         argument >= 0,
         argumentName, argument, message ?? $"{nameof(argument)} can not be negative or zero.");
 }
Exemplo n.º 16
0
 /// <summary>
 /// 检查整数是否越界
 /// </summary>
 /// <param name="argument"></param>
 /// <param name="min"></param>
 /// <param name="max"></param>
 /// <param name="argumentName"></param>
 /// <param name="message"></param>
 public static void IsNotOutOfRange(int argument, int min, int max, string argumentName, string message = null)
 {
     AssertionJudgment.Require2 <ArgumentOutOfRangeException>(
         NumericJudgment.IsBetween(argument, min, max),
         argumentName, argument, message ?? $"{nameof(argument)} is not between {min} and {max}.");
 }