Ejemplo 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)
        {
            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));
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 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()));
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Is numeric type
 /// </summary>
 /// <param name="typeInfo"></param>
 /// <returns></returns>
 public static bool IsNumericType(TypeInfo typeInfo) => TypeJudgment.IsNumericType(typeInfo);
Ejemplo n.º 5
0
 /// <summary>
 /// Is numeric type
 /// </summary>
 /// <param name="type"></param>
 /// <returns></returns>
 public static bool IsNumericType(Type type) => TypeJudgment.IsNumericType(type);
Ejemplo n.º 6
0
 /// <summary>
 /// Is numeric type
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <returns></returns>
 public static bool IsNumericType <T>() => TypeJudgment.IsNumericType <T>();