37 lines
1.6 KiB
C#
37 lines
1.6 KiB
C#
namespace adas_core.Domain.Utils;
|
|
|
|
/// <summary>
|
|
/// Provides a collection of static utility methods for performing common numeric operations.
|
|
/// </summary>
|
|
public static class NumberUtils
|
|
{
|
|
/// <summary>
|
|
/// Determines whether the specified object is an instance of any built-in numeric type, including signed and unsigned integral types as well as floating-point and decimal types.
|
|
/// </summary>
|
|
/// <param name="value">The object to evaluate.</param>
|
|
/// <returns><c>true</c> if <paramref name="value"/> is one of the supported numeric types (sbyte, byte, short, ushort, int, uint, long, ulong, float, double, or decimal); otherwise, <c>false</c>.</returns>
|
|
public static bool IsNumber(this object value)
|
|
{
|
|
return value is sbyte
|
|
|| value is byte
|
|
|| value is short
|
|
|| value is ushort
|
|
|| value is int
|
|
|| value is uint
|
|
|| value is long
|
|
|| value is ulong
|
|
|| value is float
|
|
|| value is double
|
|
|| value is decimal;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts the specified object to a double-precision floating-point number using the underlying <see cref="Convert.ToDouble(object)"/> conversion.
|
|
/// </summary>
|
|
/// <param name="value">The object to convert to a <see cref="double"/>.</param>
|
|
/// <returns>A <see cref="double"/> that represents the converted value.</returns>
|
|
public static double ToDouble(this object value)
|
|
{
|
|
return Convert.ToDouble(value);
|
|
}
|
|
} |