/// <summary> /// Invokes <see cref="MessagePackObject.AsInt64()"/> in deserializaton manner. /// </summary> /// <param name="source"><see cref="MessagePackObject"/>.</param> /// <returns>A deserialized value.</returns> /// <exception cref="SerializationException"><paramref name="source"/> is not expected type.</exception> public static long DeserializeAsInt64( this MessagePackObject source ) { try { return source.AsInt64(); } catch ( InvalidOperationException ex ) { throw new SerializationException( String.Format( CultureInfo.CurrentCulture, "The unpacked value is not expected type. {0}", ex.Message ), ex ); } }
/// <summary> /// Determines whether the value is even /// </summary> /// <param name = "value">The Value</param> /// <returns>true or false</returns> public static bool IsEven(this Int32 value) { return value.AsInt64().IsEven(); }
/// <summary>Checks whether the value is in range or returns the default value</summary> /// <param name="value">The Value</param> /// <param name="minValue">The minimum value</param> /// <param name="maxValue">The maximum value</param> /// <param name="defaultValue">The default value</param> public static Int32 InRange(this Int32 value, Int32 minValue, Int32 maxValue, Int32 defaultValue) { return (Int32) value.AsInt64().InRange(minValue, maxValue, defaultValue); }
/// <summary>Checks whether the value is in range</summary> /// <param name="value">The Value</param> /// <param name="minValue">The minimum value</param> /// <param name="maxValue">The maximum value</param> public static bool InRange(this Int32 value, Int32 minValue, Int32 maxValue) { return value.AsInt64().InRange(minValue, maxValue); }
/// <summary> /// /// </summary> /// <param name="value"></param> /// <returns></returns> public static Int64 Factorial(this Int32 value) { return value.AsInt64().Factorial(); }
/// <summary> /// Converts the value to ordinal String with specified format. (English) /// </summary> /// <param name="value">Object value</param> /// <param name="format">A standard or custom format String that is supported by the object to be formatted.</param> /// <returns>Returns String containing ordinal indicator adjacent to a numeral denoting. (English)</returns> public static String ToOrdinal(this Int32 value, String format) { return value.AsInt64().ToOrdinal(format); }
/// <summary> /// Converts the value to ordinal String. (English) /// </summary> /// <param name="value">Object value</param> /// <returns>Returns String containing ordinal indicator adjacent to a numeral denoting. (English)</returns> public static String ToOrdinal(this Int32 value) { return value.AsInt64().ToOrdinal(); }
/// <summary> /// Performs the specified action n times based on the underlying Int32 value. /// </summary> /// <param name = "value">The value.</param> /// <param name = "action">The action.</param> public static void Times(this Int32 value, Action action) { //for (Int32 i = 0; i < value; ++i) // action(); value.AsInt64().Times(action); }
/// <summary> /// A prime number (or a prime) is a natural number that has exactly two distinct natural number divisors: 1 and itself. /// </summary> /// <param name="value">Object value</param> /// <returns>Returns true if the value is a prime number.</returns> public static bool IsPrime(this Int32 value) { return value.AsInt64().IsPrime(); }