示例#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)
        {
            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));
        }
        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));
        }
示例#3
0
        public void IsNumericTest()
        {
            Assert.True(TypeJudgment.IsNumericType(1.GetType()));
            Assert.True(TypeJudgment.IsNumericType(1D.GetType()));
            Assert.True(TypeJudgment.IsNumericType(1F.GetType()));
            Assert.True(TypeJudgment.IsNumericType(1M.GetType()));
            Assert.True(TypeJudgment.IsNumericType(1.001M.GetType()));
            Assert.True(TypeJudgment.IsNumericType(1L.GetType()));

            Assert.True(TypeJudgment.IsNumericType(1.GetType().GetTypeInfo()));
            Assert.True(TypeJudgment.IsNumericType(1D.GetType().GetTypeInfo()));
            Assert.True(TypeJudgment.IsNumericType(1F.GetType().GetTypeInfo()));
            Assert.True(TypeJudgment.IsNumericType(1M.GetType().GetTypeInfo()));
            Assert.True(TypeJudgment.IsNumericType(1.001M.GetType().GetTypeInfo()));
            Assert.True(TypeJudgment.IsNumericType(1L.GetType().GetTypeInfo()));
        }
示例#4
0
 /// <summary>
 /// Is numeric type
 /// </summary>
 /// <param name="typeInfo"></param>
 /// <returns></returns>
 public static bool IsNumericType(TypeInfo typeInfo) => TypeJudgment.IsNumericType(typeInfo);
示例#5
0
 /// <summary>
 /// Is numeric type
 /// </summary>
 /// <param name="type"></param>
 /// <returns></returns>
 public static bool IsNumericType(Type type) => TypeJudgment.IsNumericType(type);
示例#6
0
 /// <summary>
 /// Is numeric type
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <returns></returns>
 public static bool IsNumericType <T>() => TypeJudgment.IsNumericType <T>();