Beispiel #1
0
 public override Task Invoke(ParameterAspectContext context, ParameterAspectDelegate next)
 {
     if (context.Parameter.IsIntType())
     {
         context.Parameter.TryTo <int?>().SafeValue().CheckNegative(context.Parameter.Name, Message);
     }
     else if (context.Parameter.IsLongType())
     {
         context.Parameter.TryTo <long?>().SafeValue().CheckNegative(context.Parameter.Name, Message);
     }
     else if (context.Parameter.IsFloatType())
     {
         context.Parameter.TryTo <float?>().SafeValue().CheckNegative(context.Parameter.Name, Message);
     }
     else if (context.Parameter.IsDoubleType())
     {
         context.Parameter.TryTo <double?>().SafeValue().CheckNegative(context.Parameter.Name, Message);
     }
     else if (context.Parameter.IsDecimalType())
     {
         context.Parameter.TryTo <decimal?>().SafeValue().CheckNegative(context.Parameter.Name, Message);
     }
     else if (context.Parameter.IsTimeSpanType())
     {
         context.Parameter.TryTo <TimeSpan?>().SafeValue().CheckNegative(context.Parameter.Name, Message);
     }
     return(next(context));
 }
Beispiel #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)
 {
     AssertionJudgment.Require2Validation <ArgumentInvalidException>(
         context.Parameter.Type.Is(TypeClass.StringClass),
         Message, context.Parameter.Name);
     return(next(context));
 }
Beispiel #3
0
        /// <summary>
        /// Invoke <br />
        /// 执行
        /// </summary>
        /// <param name="context"></param>
        /// <param name="next"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentInvalidException"></exception>
        public override Task Invoke(ParameterAspectContext context, ParameterAspectDelegate next)
        {
            var valid = IsValid(context.Parameter);

            ValidationExceptionHelper.WrapAndRaise <ArgumentInvalidException>(valid, ErrorMessage, GetParamName(context.Parameter));
            return(next(context));
        }
 /// <summary>
 /// 执行
 /// </summary>
 public override Task Invoke(ParameterAspectContext context, ParameterAspectDelegate next)
 {
     if (string.IsNullOrWhiteSpace(context.Parameter.Value.SafeString()))
     {
         throw new ArgumentNullException(context.Parameter.Name);
     }
     return(next(context));
 }
 public override Task Invoke(ParameterAspectContext context, ParameterAspectDelegate next)
 {
     if (context.Parameter.Type.Is(TypeClass.StringClass))
     {
         context.Parameter.TryTo(TypeDefault.StringEmpty).CheckBlank(context.Parameter.Name, Message);
     }
     return(next(context));
 }
Beispiel #6
0
 public override Task Invoke(ParameterAspectContext context, ParameterAspectDelegate next)
 {
     if (context.Parameter.IsDateTimeType())
     {
         context.Parameter.TryTo <DateTime?>().SafeValue().CheckValidDate(context.Parameter.Name, Message);
     }
     return(next(context));
 }
Beispiel #7
0
 /// <summary>
 /// 执行
 /// </summary>
 public override Task Invoke(ParameterAspectContext context, ParameterAspectDelegate next)
 {
     if (context.Parameter.Value == null)
     {
         throw new ArgumentNullException(context.Parameter.Name);
     }
     return(next(context));
 }
Beispiel #8
0
 public override Task Invoke(IParameterDescriptor parameter, ParameterAspectContext context, ParameterAspectDelegate next)
 {
     if (string.IsNullOrEmpty(parameter.Value?.ToString()))
     {
         throw new ArgumentNullException($"Invalid parameter. {parameter.Name} cannot be null or empty");
     }
     return(next(parameter, context));
 }
Beispiel #9
0
 public override Task Invoke(ParameterAspectContext context, ParameterAspectDelegate next)
 {
     if (context.Parameter.Type.IsNot(TypeClass.StringClass))
     {
         throw new ArgumentException(Message, context.Parameter.Name);
     }
     return(next(context));
 }
Beispiel #10
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));
        }
Beispiel #11
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));
        }
Beispiel #12
0
        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);

            if (condition)
            {
                throw new ArgumentException(Message, context.Parameter.Name);
            }
            return(next(context));
        }
        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);

            if (condition)
            {
                throw new ArgumentException(Message, context.Parameter.Name);
            }
            return(next(context));
        }
        public override Task Invoke(ParameterAspectContext context, ParameterAspectDelegate next)
        {
            var parameter = context.Parameter;

            if (parameter.ParameterInfo.ParameterType == typeof(string).MakeByRefType())
            {
                parameter.Value = "lemon";
            }
            if (parameter.ParameterInfo.ParameterType == typeof(int).MakeByRefType())
            {
                parameter.Value = 22;
            }

            return(next(context));
        }
 public override Task Invoke(ParameterAspectContext context, ParameterAspectDelegate next)
 {
     if (context.Parameter.IsIntType())
     {
         context.Parameter.TryTo <int?>().SafeValue().CheckOutOfRange(IntMin, IntMax, context.Parameter.Name, Message);
     }
     else if (context.Parameter.IsLongType())
     {
         context.Parameter.TryTo <long?>().SafeValue().CheckOutOfRange(LongMin, LongMax, context.Parameter.Name, Message);
     }
     else if (context.Parameter.IsFloatType())
     {
         context.Parameter.TryTo <float?>().SafeValue().CheckOutOfRange(FloatMin, FloatMax, context.Parameter.Name, Message);
     }
     else if (context.Parameter.IsDoubleType())
     {
         context.Parameter.TryTo <double?>().SafeValue().CheckOutOfRange(DoubleMin, DoubleMax, context.Parameter.Name, Message);
     }
     else if (context.Parameter.IsDecimalType())
     {
         context.Parameter.TryTo <decimal?>().SafeValue().CheckOutOfRange(DecimalMin, DecimalMax, context.Parameter.Name, Message);
     }
     return(next(context));
 }
Beispiel #16
0
 /// <summary>
 /// 执行
 /// </summary>
 public override async Task Invoke(ParameterAspectContext context, ParameterAspectDelegate next)
 {
     Validate(context.Parameter);
     await next(context);
 }