/// <summary> /// Gets a value indicating if the type is a numeric type in any of the specified numeric classes. /// </summary> /// <param name="this">The source type.</param> /// <param name="numericClass">The classes of numeric types to check.</param> /// <returns> /// <c>true</c> if the type is a numeric type in any of the specified numeric classes, otherwise <c>false</c>. /// </returns> /// <exception cref="ArgumentNullException"><paramref name="this"/> is <c>null</c>.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="numericClass"/> is invalid.</exception> /// <example> /// <code language="csharp"> /// typeof(int).IsNumeric(NumericClass.FloatingPoint); // false /// typeof(int).IsNumeric(NumericClass.Integral | NumericClass.FloatingPoint); // true /// typeof(BigInteger).IsNumeric(NumericClass.Integral); // true /// typeof(Matrix3x2).IsNumeric(NumericClass.Vector); // true /// </code> /// </example> public static bool IsNumeric([NotNull] this Type @this, NumericClass numericClass) { if (!numericClass.IsValid()) { throw new ArgumentOutOfRangeException(nameof(numericClass), numericClass, null); } #if NETSTANDARD1_4 var typeInfo = @this.GetTypeInfo(); var type = typeInfo.IsGenericType ? typeInfo.GetGenericTypeDefinition() : @this; #else var type = @this.IsGenericType ? @this.GetGenericTypeDefinition() : @this; #endif return(NumericEx.TypeMap.TryGetValue(type, out var actualClass) && numericClass.HasAnyFlags(actualClass)); }
private void txtCash_KeyPress(object sender, KeyPressEventArgs e) { NumericClass.NumberAccpter(sender, e, true); }
private void txtID_KeyPress(object sender, KeyPressEventArgs e) { NumericClass.NumberAccpter(sender, e, false); }
public bool ReturnsExpectedResult(Type type, NumericClass numericClass) => type.IsNumeric(numericClass);
public void NullThisThrowsArgumentNullException(NumericClass numericClass) => Should.Throw <ArgumentNullException>(() => default(Type).IsNumeric(numericClass)) .ParamName.ShouldBe("this");