/// <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)); }
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())); }
/// <summary> /// Is numeric type /// </summary> /// <param name="typeInfo"></param> /// <returns></returns> public static bool IsNumericType(TypeInfo typeInfo) => TypeJudgment.IsNumericType(typeInfo);
/// <summary> /// Is numeric type /// </summary> /// <param name="type"></param> /// <returns></returns> public static bool IsNumericType(Type type) => TypeJudgment.IsNumericType(type);
/// <summary> /// Is numeric type /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public static bool IsNumericType <T>() => TypeJudgment.IsNumericType <T>();