From 96f68343ce81df4d9cc2c4dd9ece0840517d2cd2 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Sun, 17 Jan 2021 12:48:19 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Consolidate=20methods=20into=20s?= =?UTF-8?q?ensible=20partials?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BooleanExtensions.Conversions.Unsigned.cs | 132 +++++++++++ .../BooleanExtensions.Conversions.cs | 217 ++++++++++++++++++ .../BooleanExtensions.ToByte.cs | 19 -- .../BooleanExtensions.ToDecimal.cs | 19 -- .../BooleanExtensions.ToDouble.cs | 19 -- .../BooleanExtensions.ToInt16.cs | 19 -- .../BooleanExtensions.ToInt32.cs | 19 -- .../BooleanExtensions.ToInt64.cs | 19 -- .../BooleanExtensions.ToSingle.cs | 19 -- .../BooleanExtensions.ToUInt16.cs | 19 -- .../BooleanExtensions.ToUInt32.cs | 19 -- .../BooleanExtensions.ToUInt64.cs | 19 -- 12 files changed, 349 insertions(+), 190 deletions(-) create mode 100644 X10D/src/BooleanExtensions/BooleanExtensions.Conversions.Unsigned.cs create mode 100644 X10D/src/BooleanExtensions/BooleanExtensions.Conversions.cs delete mode 100644 X10D/src/BooleanExtensions/BooleanExtensions.ToByte.cs delete mode 100644 X10D/src/BooleanExtensions/BooleanExtensions.ToDecimal.cs delete mode 100644 X10D/src/BooleanExtensions/BooleanExtensions.ToDouble.cs delete mode 100644 X10D/src/BooleanExtensions/BooleanExtensions.ToInt16.cs delete mode 100644 X10D/src/BooleanExtensions/BooleanExtensions.ToInt32.cs delete mode 100644 X10D/src/BooleanExtensions/BooleanExtensions.ToInt64.cs delete mode 100644 X10D/src/BooleanExtensions/BooleanExtensions.ToSingle.cs delete mode 100644 X10D/src/BooleanExtensions/BooleanExtensions.ToUInt16.cs delete mode 100644 X10D/src/BooleanExtensions/BooleanExtensions.ToUInt32.cs delete mode 100644 X10D/src/BooleanExtensions/BooleanExtensions.ToUInt64.cs diff --git a/X10D/src/BooleanExtensions/BooleanExtensions.Conversions.Unsigned.cs b/X10D/src/BooleanExtensions/BooleanExtensions.Conversions.Unsigned.cs new file mode 100644 index 0000000..3c8ac1c --- /dev/null +++ b/X10D/src/BooleanExtensions/BooleanExtensions.Conversions.Unsigned.cs @@ -0,0 +1,132 @@ +using System; +using System.Runtime.CompilerServices; + +namespace X10D.BooleanExtensions +{ + public static partial class BooleanExtensions + { + /// + /// Converts the current Boolean value to the equivalent 8-bit signed integer. + /// + /// The Boolean value to convert. + /// + /// 1 if is + /// -or- + /// 0 otherwise. + /// + /// + /// The following example illustrates the conversion of to values. + /// + /// bool falseFlag = false; + /// bool trueFlag = true; + /// + /// Console.WriteLine("{0} converts to {1}.", falseFlag, + /// falseFlag.ToSByte()); + /// Console.WriteLine("{0} converts to {1}.", trueFlag, + /// trueFlag.ToSByte()); + /// // The example displays the following output: + /// // False converts to 0. + /// // True converts to 1. + /// + /// + [CLSCompliant(false)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static sbyte ToSByte(this bool value) + { + return value ? 1 : 0; + } + + /// + /// Converts the current Boolean value to the equivalent 16-bit unsigned integer. + /// + /// The Boolean value to convert. + /// + /// 1 if is + /// -or- + /// 0 otherwise. + /// + /// + /// The following example illustrates the conversion of to values. + /// + /// bool falseFlag = false; + /// bool trueFlag = true; + /// + /// Console.WriteLine("{0} converts to {1}.", falseFlag, + /// falseFlag.ToUInt16()); + /// Console.WriteLine("{0} converts to {1}.", trueFlag, + /// trueFlag.ToUInt16()); + /// // The example displays the following output: + /// // False converts to 0. + /// // True converts to 1. + /// + /// + [CLSCompliant(false)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ushort ToUInt16(this bool value) + { + return value.ToByte(); + } + + /// + /// Converts the current Boolean value to the equivalent 32-bit unsigned integer. + /// + /// The Boolean value to convert. + /// + /// 1 if is + /// -or- + /// 0 otherwise. + /// + /// + /// The following example illustrates the conversion of to values. + /// + /// bool falseFlag = false; + /// bool trueFlag = true; + /// + /// Console.WriteLine("{0} converts to {1}.", falseFlag, + /// falseFlag.ToUInt32()); + /// Console.WriteLine("{0} converts to {1}.", trueFlag, + /// trueFlag.ToUInt32()); + /// // The example displays the following output: + /// // False converts to 0. + /// // True converts to 1. + /// + /// + [CLSCompliant(false)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static uint ToUInt32(this bool value) + { + return value.ToByte(); + } + + /// + /// Converts the current Boolean value to the equivalent 64-bit unsigned integer. + /// + /// The Boolean value to convert. + /// + /// 1 if is + /// -or- + /// 0 otherwise. + /// + /// + /// The following example illustrates the conversion of to values. + /// + /// bool falseFlag = false; + /// bool trueFlag = true; + /// + /// Console.WriteLine("{0} converts to {1}.", falseFlag, + /// falseFlag.ToUInt64()); + /// Console.WriteLine("{0} converts to {1}.", trueFlag, + /// trueFlag.ToUInt64()); + /// // The example displays the following output: + /// // False converts to 0. + /// // True converts to 1. + /// + /// + [CLSCompliant(false)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ulong ToUInt64(this bool value) + { + return value.ToByte(); + } + } +} diff --git a/X10D/src/BooleanExtensions/BooleanExtensions.Conversions.cs b/X10D/src/BooleanExtensions/BooleanExtensions.Conversions.cs new file mode 100644 index 0000000..d1cf318 --- /dev/null +++ b/X10D/src/BooleanExtensions/BooleanExtensions.Conversions.cs @@ -0,0 +1,217 @@ +using System.Runtime.CompilerServices; + +namespace X10D.BooleanExtensions +{ + public static partial class BooleanExtensions + { + /// + /// Converts the current Boolean value to the equivalent 8-bit unsigned integer. + /// + /// The Boolean value to convert. + /// + /// 1 if is + /// -or- + /// 0 otherwise. + /// + /// + /// The following example illustrates the conversion of to values. + /// + /// bool falseFlag = false; + /// bool trueFlag = true; + /// + /// Console.WriteLine("{0} converts to {1}.", falseFlag, + /// falseFlag.ToByte()); + /// Console.WriteLine("{0} converts to {1}.", trueFlag, + /// trueFlag.ToByte()); + /// // The example displays the following output: + /// // False converts to 0. + /// // True converts to 1. + /// + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static byte ToByte(this bool value) + { + return value ? 1 : 0; + } + + /// + /// Converts the current Boolean value to the equivalent decimal number. + /// + /// The Boolean value to convert. + /// + /// 1 if is + /// -or- + /// 0 otherwise. + /// + /// + /// The following example illustrates the conversion of to values. + /// + /// bool falseFlag = false; + /// bool trueFlag = true; + /// + /// Console.WriteLine("{0} converts to {1}.", falseFlag, + /// falseFlag.ToDouble()); + /// Console.WriteLine("{0} converts to {1}.", trueFlag, + /// trueFlag.ToDouble()); + /// // The example displays the following output: + /// // False converts to 0. + /// // True converts to 1. + /// + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static decimal ToDecimal(this bool value) + { + return value.ToByte(); + } + + /// + /// Converts the current Boolean value to the equivalent double-precision floating-point number. + /// + /// The Boolean value to convert. + /// + /// 1 if is + /// -or- + /// 0 otherwise. + /// + /// + /// The following example illustrates the conversion of to values. + /// + /// bool falseFlag = false; + /// bool trueFlag = true; + /// + /// Console.WriteLine("{0} converts to {1}.", falseFlag, + /// falseFlag.ToDouble()); + /// Console.WriteLine("{0} converts to {1}.", trueFlag, + /// trueFlag.ToDouble()); + /// // The example displays the following output: + /// // False converts to 0. + /// // True converts to 1. + /// + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long ToDouble(this bool value) + { + return value.ToByte(); + } + + /// + /// Converts the current Boolean value to the equivalent 16-bit signed integer. + /// + /// The Boolean value to convert. + /// + /// 1 if is + /// -or- + /// 0 otherwise. + /// + /// + /// The following example illustrates the conversion of to values. + /// + /// bool falseFlag = false; + /// bool trueFlag = true; + /// + /// Console.WriteLine("{0} converts to {1}.", falseFlag, + /// falseFlag.ToInt16()); + /// Console.WriteLine("{0} converts to {1}.", trueFlag, + /// trueFlag.ToInt16()); + /// // The example displays the following output: + /// // False converts to 0. + /// // True converts to 1. + /// + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static short ToInt16(this bool value) + { + return value.ToByte(); + } + + /// + /// Converts the current Boolean value to the equivalent 32-bit signed integer. + /// + /// The Boolean value to convert. + /// + /// 1 if is + /// -or- + /// 0 otherwise. + /// + /// + /// The following example illustrates the conversion of to values. + /// + /// bool falseFlag = false; + /// bool trueFlag = true; + /// + /// Console.WriteLine("{0} converts to {1}.", falseFlag, + /// falseFlag.ToInt32()); + /// Console.WriteLine("{0} converts to {1}.", trueFlag, + /// trueFlag.ToInt32()); + /// // The example displays the following output: + /// // False converts to 0. + /// // True converts to 1. + /// + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int ToInt32(this bool value) + { + return value.ToByte(); + } + + /// + /// Converts the current Boolean value to the equivalent 64-bit signed integer. + /// + /// The Boolean value to convert. + /// + /// 1 if is + /// -or- + /// 0 otherwise. + /// + /// + /// The following example illustrates the conversion of to values. + /// + /// bool falseFlag = false; + /// bool trueFlag = true; + /// + /// Console.WriteLine("{0} converts to {1}.", falseFlag, + /// falseFlag.ToInt64()); + /// Console.WriteLine("{0} converts to {1}.", trueFlag, + /// trueFlag.ToInt64()); + /// // The example displays the following output: + /// // False converts to 0. + /// // True converts to 1. + /// + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long ToInt64(this bool value) + { + return value.ToByte(); + } + + /// + /// Converts the current Boolean value to the equivalent single-precision floating-point number. + /// + /// The Boolean value to convert. + /// + /// 1 if is + /// -or- + /// 0 otherwise. + /// + /// + /// The following example illustrates the conversion of to values. + /// + /// bool falseFlag = false; + /// bool trueFlag = true; + /// + /// Console.WriteLine("{0} converts to {1}.", falseFlag, + /// falseFlag.ToSingle()); + /// Console.WriteLine("{0} converts to {1}.", trueFlag, + /// trueFlag.ToSingle()); + /// // The example displays the following output: + /// // False converts to 0. + /// // True converts to 1. + /// + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float ToSingle(this bool value) + { + return value.ToByte(); + } + } +} diff --git a/X10D/src/BooleanExtensions/BooleanExtensions.ToByte.cs b/X10D/src/BooleanExtensions/BooleanExtensions.ToByte.cs deleted file mode 100644 index 248de01..0000000 --- a/X10D/src/BooleanExtensions/BooleanExtensions.ToByte.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace X10D.BooleanExtensions -{ - public static partial class BooleanExtensions - { - /// - /// Converts the current to a 1-byte unsigned integer representing its truthiness. - /// - /// The value to convert. - /// - /// 1 if is - /// -or- - /// 0 otherwise. - /// - public static byte ToByte(this bool value) - { - return value ? 1 : 0; - } - } -} diff --git a/X10D/src/BooleanExtensions/BooleanExtensions.ToDecimal.cs b/X10D/src/BooleanExtensions/BooleanExtensions.ToDecimal.cs deleted file mode 100644 index aba4031..0000000 --- a/X10D/src/BooleanExtensions/BooleanExtensions.ToDecimal.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace X10D.BooleanExtensions -{ - public static partial class BooleanExtensions - { - /// - /// Converts the current to a decimal floating-point number representing its truthiness. - /// - /// The value to convert. - /// - /// 1 if is - /// -or- - /// 0 otherwise. - /// - public static decimal ToDecimal(this bool value) - { - return value.ToByte(); - } - } -} diff --git a/X10D/src/BooleanExtensions/BooleanExtensions.ToDouble.cs b/X10D/src/BooleanExtensions/BooleanExtensions.ToDouble.cs deleted file mode 100644 index 6532dbb..0000000 --- a/X10D/src/BooleanExtensions/BooleanExtensions.ToDouble.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace X10D.BooleanExtensions -{ - public static partial class BooleanExtensions - { - /// - /// Converts the current to a double-precision floating-point number representing its truthiness. - /// - /// The value to convert. - /// - /// 1 if is - /// -or- - /// 0 otherwise. - /// - public static long ToDouble(this bool value) - { - return value.ToByte(); - } - } -} diff --git a/X10D/src/BooleanExtensions/BooleanExtensions.ToInt16.cs b/X10D/src/BooleanExtensions/BooleanExtensions.ToInt16.cs deleted file mode 100644 index bea5419..0000000 --- a/X10D/src/BooleanExtensions/BooleanExtensions.ToInt16.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace X10D.BooleanExtensions -{ - public static partial class BooleanExtensions - { - /// - /// Converts the current to a 2-byte signed integer representing its truthiness. - /// - /// The value to convert. - /// - /// 1 if is - /// -or- - /// 0 otherwise. - /// - public static short ToInt16(this bool value) - { - return value.ToByte(); - } - } -} diff --git a/X10D/src/BooleanExtensions/BooleanExtensions.ToInt32.cs b/X10D/src/BooleanExtensions/BooleanExtensions.ToInt32.cs deleted file mode 100644 index d98015d..0000000 --- a/X10D/src/BooleanExtensions/BooleanExtensions.ToInt32.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace X10D.BooleanExtensions -{ - public static partial class BooleanExtensions - { - /// - /// Converts the current to a 4-byte signed integer representing its truthiness. - /// - /// The value to convert. - /// - /// 1 if is - /// -or- - /// 0 otherwise. - /// - public static int ToInt32(this bool value) - { - return value.ToByte(); - } - } -} diff --git a/X10D/src/BooleanExtensions/BooleanExtensions.ToInt64.cs b/X10D/src/BooleanExtensions/BooleanExtensions.ToInt64.cs deleted file mode 100644 index aae2858..0000000 --- a/X10D/src/BooleanExtensions/BooleanExtensions.ToInt64.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace X10D.BooleanExtensions -{ - public static partial class BooleanExtensions - { - /// - /// Converts the current to an 8-byte signed integer representing its truthiness. - /// - /// The value to convert. - /// - /// 1 if is - /// -or- - /// 0 otherwise. - /// - public static long ToInt64(this bool value) - { - return value.ToByte(); - } - } -} diff --git a/X10D/src/BooleanExtensions/BooleanExtensions.ToSingle.cs b/X10D/src/BooleanExtensions/BooleanExtensions.ToSingle.cs deleted file mode 100644 index 9dba0ea..0000000 --- a/X10D/src/BooleanExtensions/BooleanExtensions.ToSingle.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace X10D.BooleanExtensions -{ - public static partial class BooleanExtensions - { - /// - /// Converts the current to a single-precision floating-point number representing its truthiness. - /// - /// The value to convert. - /// - /// 1 if is - /// -or- - /// 0 otherwise. - /// - public static float ToSingle(this bool value) - { - return value.ToByte(); - } - } -} diff --git a/X10D/src/BooleanExtensions/BooleanExtensions.ToUInt16.cs b/X10D/src/BooleanExtensions/BooleanExtensions.ToUInt16.cs deleted file mode 100644 index 32bd726..0000000 --- a/X10D/src/BooleanExtensions/BooleanExtensions.ToUInt16.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace X10D.BooleanExtensions -{ - public static partial class BooleanExtensions - { - /// - /// Converts the current to a 2-byte unsigned integer representing its truthiness. - /// - /// The value to convert. - /// - /// 1 if is - /// -or- - /// 0 otherwise. - /// - public static ushort ToUInt16(this bool value) - { - return value.ToByte(); - } - } -} diff --git a/X10D/src/BooleanExtensions/BooleanExtensions.ToUInt32.cs b/X10D/src/BooleanExtensions/BooleanExtensions.ToUInt32.cs deleted file mode 100644 index 2f7ece7..0000000 --- a/X10D/src/BooleanExtensions/BooleanExtensions.ToUInt32.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace X10D.BooleanExtensions -{ - public static partial class BooleanExtensions - { - /// - /// Converts the current to a 4-byte unsigned integer representing its truthiness. - /// - /// The value to convert. - /// - /// 1 if is - /// -or- - /// 0 otherwise. - /// - public static uint ToUInt32(this bool value) - { - return value.ToByte(); - } - } -} diff --git a/X10D/src/BooleanExtensions/BooleanExtensions.ToUInt64.cs b/X10D/src/BooleanExtensions/BooleanExtensions.ToUInt64.cs deleted file mode 100644 index 1acdf19..0000000 --- a/X10D/src/BooleanExtensions/BooleanExtensions.ToUInt64.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace X10D.BooleanExtensions -{ - public static partial class BooleanExtensions - { - /// - /// Converts the current to an 8-byte unsigned integer representing its truthiness. - /// - /// The value to convert. - /// - /// 1 if is - /// -or- - /// 0 otherwise. - /// - public static ulong ToUInt64(this bool value) - { - return value.ToByte(); - } - } -}