IsFixedPointNumeric() public static method

Checks the type of the object, returning true if the object is a fixed point numeric type.
public static IsFixedPointNumeric ( Object obj ) : bool
obj Object The object to check
return bool
Beispiel #1
0
        private Range LinearRange(object value)
        {
            if (Amount is double || value is double)
            {
                var amount = Convert.ToDouble(Amount);
                var v      = Convert.ToDouble(value);
                return(new Range(v - amount, v + amount));
            }

            if (Amount is float || value is float)
            {
                var amount = Convert.ToSingle(Amount);
                var v      = Convert.ToSingle(value);
                return(new Range(v - amount, v + amount));
            }

            if (Amount is decimal || value is decimal)
            {
                var amount = Convert.ToDecimal(Amount);
                var v      = Convert.ToDecimal(value);
                return(new Range(v - amount, v + amount));
            }

            if (Amount is ulong || value is ulong)
            {
                var amount = Convert.ToUInt64(Amount);
                var v      = Convert.ToUInt64(value);
                return(new Range(v - amount, v + amount));
            }

            if (Amount is long || value is long)
            {
                var amount = Convert.ToInt64(Amount);
                var v      = Convert.ToInt64(value);
                return(new Range(v - amount, v + amount));
            }

            if (Amount is uint || value is uint)
            {
                var amount = Convert.ToUInt32(Amount);
                var v      = Convert.ToUInt32(value);
                return(new Range(v - amount, v + amount));
            }

            if (Numerics.IsFixedPointNumeric(Amount) && Numerics.IsFixedPointNumeric(value))
            {
                var amount = Convert.ToInt32(Amount);
                var v      = Convert.ToInt32(value);
                return(new Range(v - amount, v + amount));
            }

            throw new InvalidOperationException("Cannot create range for a non-numeric value");
        }
Beispiel #2
0
 public void FailsOnDecimalIsPartOfIsFixedPointNumericMethod()
 {
     Assert.IsFalse(Numerics.IsFixedPointNumeric(1000m));
 }