diff --git a/X10D/src/Int16Extensions.cs b/X10D/src/Int16Extensions.cs deleted file mode 100644 index 3782ec0..0000000 --- a/X10D/src/Int16Extensions.cs +++ /dev/null @@ -1,189 +0,0 @@ -using System; - -namespace X10D -{ - /// - /// Extension methods for . - /// - public static class Int16Extensions - { - /// - /// 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 short Clamp(this short value, short min, short 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 ushort Clamp(this ushort value, ushort min, ushort 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 short 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 ushort number) - { - return BitConverter.GetBytes(number); - } - - /// - /// Converts the to a []. - /// - /// The number to convert. - /// Returns a []. - public static byte[] GetBytes(this short number) - { - return BitConverter.GetBytes(number); - } - - /// - /// Determines if the is even. - /// - /// The number. - /// - /// Returns if is even, - /// otherwise. - /// - public static bool IsEven(this short number) - { - return ((long)number).IsEven(); - } - - /// - /// Determines if the is even. - /// - /// The number. - /// - /// Returns if is even, - /// otherwise. - /// - [CLSCompliant(false)] - public static bool IsEven(this ushort number) - { - return ((ulong)number).IsEven(); - } - - /// - /// Determines if the is odd. - /// - /// The number. - /// - /// Returns if is odd, - /// otherwise. - /// - public static bool IsOdd(this short number) - { - return !number.IsEven(); - } - - /// - /// Determines if the is odd. - /// - /// The number. - /// - /// Returns if is odd, - /// otherwise. - /// - [CLSCompliant(false)] - public static bool IsOdd(this ushort number) - { - return !number.IsEven(); - } - - /// - /// Determines if the is a prime number. - /// - /// The number. - /// - /// Returns if is prime, - /// otherwise. - /// - public static bool IsPrime(this short number) - { - return ((long)number).IsPrime(); - } - - /// - /// Determines if the is a prime number. - /// - /// The number. - /// - /// Returns if is prime, - /// otherwise. - /// - [CLSCompliant(false)] - public static bool IsPrime(this ushort number) - { - return ((ulong)number).IsPrime(); - } - - /// - /// Gets an boolean value that represents this integer. - /// - /// The integer. - /// - /// Returns if is 0, - /// otherwise. - /// - public static bool ToBoolean(this short 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 ushort value) - { - return ((ulong)value).ToBoolean(); - } - } -} diff --git a/X10D/src/Int16Extensions/Int16Extensions.cs b/X10D/src/Int16Extensions/Int16Extensions.cs new file mode 100644 index 0000000..b792904 --- /dev/null +++ b/X10D/src/Int16Extensions/Int16Extensions.cs @@ -0,0 +1,89 @@ +using System; +using X10D.Int64Extensions; + +namespace X10D.Int16Extensions +{ + /// + /// Extension methods for . + /// + public static class Int16Extensions + { + /// + /// 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 short 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 short value) + { + return DateTimeOffset.FromUnixTimeSeconds(value); + } + + /// + /// Returns the current 16-bit signed integer value as an array of bytes. + /// + /// The number to convert. + /// An array of bytes with length 2. + public static byte[] GetBytes(this short value) + { + return BitConverter.GetBytes(value); + } + + /// + /// Returns a value indicating whether the current 16-bit signed integer is even. + /// + /// The number to check. + /// if is even, or otherwise. + public static bool IsEven(this short value) + { + return value % 2 == 0; + } + + /// + /// Returns a value indicating whether the current 16-bit signed integer is odd. + /// + /// The number to check. + /// if is odd, or otherwise. + public static bool IsOdd(this short value) + { + return !value.IsEven(); + } + + /// + /// Returns a value indicating whether the current 16-bit signed integer is prime. + /// + /// The number to check. + /// if is prime, or otherwise. + public static bool IsPrime(this short value) + { + return ((long)value).IsPrime(); + } + + /// + /// Converts the value of the current 16-bit signed integer to an equivalent value. + /// + /// The value to convert. + /// if is not zero, or otherwise. + public static bool ToBoolean(this short value) + { + return value != 0; + } + } +}