diff --git a/X10D/src/Int32Extensions.cs b/X10D/src/Int32Extensions.cs deleted file mode 100644 index 2601816..0000000 --- a/X10D/src/Int32Extensions.cs +++ /dev/null @@ -1,175 +0,0 @@ -using System; - -namespace X10D -{ - /// - /// Extension methods for . - /// - public static class Int32Extensions - { - /// - /// Clamps a value between a minimum and a maximum value. - /// - /// The value to clamp. - /// The minimum value. - /// The maximum value. - /// - /// Returns if is greater than it, - /// if is less than it, - /// or itself otherwise. - /// - public static int Clamp(this int value, int min, int max) - { - return Math.Min(Math.Max(value, min), max); - } - - /// - /// Clamps a value between a minimum and a maximum value. - /// - /// The value to clamp. - /// The minimum value. - /// The maximum value. - /// - /// Returns if is greater than it, - /// if is less than it, - /// or itself otherwise. - /// - [CLSCompliant(false)] - public static uint Clamp(this uint value, uint min, uint max) - { - return Math.Min(Math.Max(value, min), max); - } - - /// - /// Converts the to a treating it as a Unix timestamp. - /// - /// The timestamp. - /// - /// Optional. Whether or not the input value should be treated as milliseconds. Defaults - /// to .. - /// - /// - /// Returns a representing seconds since the Unix - /// epoch. - /// - public static DateTime FromUnixTimestamp(this int timestamp, bool isMillis = false) - { - return ((long)timestamp).FromUnixTimestamp(isMillis); - } - - /// - /// Converts the to a []. - /// - /// The number to convert. - /// Returns a []. - [CLSCompliant(false)] - public static byte[] GetBytes(this uint number) - { - return BitConverter.GetBytes(number); - } - - /// - /// Converts the to a []. - /// - /// The number to convert. - /// Returns a []. - public static byte[] GetBytes(this int number) - { - return BitConverter.GetBytes(number); - } - - /// - /// Determines if the is even. - /// - /// The number. - /// - /// Returns if is even, - /// otherwise. - /// - public static bool IsEven(this int number) - { - return ((long)number).IsEven(); - } - - /// - /// Determines if the is even. - /// - /// The number. - /// - /// Returns if is even, - /// otherwise. - /// - [CLSCompliant(false)] - public static bool IsEven(this uint number) - { - return ((ulong)number).IsEven(); - } - - /// - /// Determines if the is odd. - /// - /// The number. - /// - /// Returns if is odd, - /// otherwise. - /// - public static bool IsOdd(this int number) - { - return !number.IsEven(); - } - - /// - /// Determines if the is odd. - /// - /// The number. - /// - /// Returns if is odd, - /// otherwise. - /// - [CLSCompliant(false)] - public static bool IsOdd(this uint number) - { - return !number.IsEven(); - } - - /// - /// Determines if the is a prime number. - /// - /// The number. - /// - /// Returns if is prime, - /// otherwise. - /// - public static bool IsPrime(this int number) - { - return ((long)number).IsPrime(); - } - - /// - /// Gets an boolean value that represents this integer. - /// - /// The integer. - /// - /// Returns if is 0, - /// otherwise. - /// - public static bool ToBoolean(this int value) - { - return ((long)value).ToBoolean(); - } - - /// - /// Gets an boolean value that represents this integer. - /// - /// The integer. - /// - /// Returns if is 0, - /// otherwise. - /// - [CLSCompliant(false)] - public static bool ToBoolean(this uint value) - { - return ((ulong)value).ToBoolean(); - } - } -} diff --git a/X10D/src/Int32Extensions/Int32Extensions.cs b/X10D/src/Int32Extensions/Int32Extensions.cs new file mode 100644 index 0000000..bc23ebe --- /dev/null +++ b/X10D/src/Int32Extensions/Int32Extensions.cs @@ -0,0 +1,89 @@ +using System; +using X10D.Int64Extensions; + +namespace X10D.Int32Extensions +{ + /// + /// Extension methods for . + /// + public static class Int32Extensions + { + /// + /// Converts a Unix time expressed as the number of milliseconds that have elapsed since 1970-01-01T00:00:00Z to a + /// value. + /// + /// + /// A Unix time, expressed as the number of milliseconds that have elapsed since 1970-01-01T00:00:00Z (January 1, + /// 1970, at 12:00 AM UTC). For Unix times before this date, its value is negative. + /// + /// A date and time value that represents the same moment in time as the Unix time. + public static DateTimeOffset FromUnixTimeMilliseconds(this int value) + { + return DateTimeOffset.FromUnixTimeMilliseconds(value); + } + + /// + /// Converts a Unix time expressed as the number of seconds that have elapsed since 1970-01-01T00:00:00Z to a + /// value. + /// + /// + /// A Unix time, expressed as the number of seconds that have elapsed since 1970-01-01T00:00:00Z (January 1, 1970, at + /// 12:00 AM UTC). For Unix times before this date, its value is negative. + /// + /// A date and time value that represents the same moment in time as the Unix time. + public static DateTimeOffset FromUnixTimeSeconds(this int value) + { + return DateTimeOffset.FromUnixTimeSeconds(value); + } + + /// + /// Returns the current 32-bit signed integer value as an array of bytes. + /// + /// The number to convert. + /// An array of bytes with length 4. + public static byte[] GetBytes(this int value) + { + return BitConverter.GetBytes(value); + } + + /// + /// Returns a value indicating whether the current 32-bit signed integer is even. + /// + /// The number to check. + /// if is even, or otherwise. + public static bool IsEven(this int value) + { + return value % 2 == 0; + } + + /// + /// Returns a value indicating whether the current 32-bit signed integer is odd. + /// + /// The number to check. + /// if is odd, or otherwise. + public static bool IsOdd(this int value) + { + return !value.IsEven(); + } + + /// + /// Returns a value indicating whether the current 32-bit signed integer is prime. + /// + /// The number to check. + /// if is prime, or otherwise. + public static bool IsPrime(this int value) + { + return ((long)value).IsPrime(); + } + + /// + /// Converts the value of the current 32-bit signed integer to an equivalent value. + /// + /// The value to convert. + /// if is not zero, or otherwise. + public static bool ToBoolean(this int value) + { + return value != 0; + } + } +}