From 45716975891857e8ee5489f51e8d741a7a81aae6 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Fri, 12 Mar 2021 13:24:30 +0000 Subject: [PATCH] (#15) (#39) Match unsigned impl with signed --- .../BooleanExtensions.Unsigned.cs | 62 +++++++------------ 1 file changed, 23 insertions(+), 39 deletions(-) diff --git a/X10D/src/BooleanExtensions/BooleanExtensions.Unsigned.cs b/X10D/src/BooleanExtensions/BooleanExtensions.Unsigned.cs index 4f17069..de02a17 100644 --- a/X10D/src/BooleanExtensions/BooleanExtensions.Unsigned.cs +++ b/X10D/src/BooleanExtensions/BooleanExtensions.Unsigned.cs @@ -8,26 +8,22 @@ namespace X10D.BooleanExtensions /// Converts the current Boolean value to the equivalent 8-bit signed integer. /// /// The Boolean value to convert. - /// - /// 1 if is - /// -or- - /// 0 otherwise. - /// + /// 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()); + /// 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)] public static sbyte ToSByte(this bool value) { @@ -38,90 +34,78 @@ namespace X10D.BooleanExtensions /// Converts the current Boolean value to the equivalent 16-bit unsigned integer. /// /// The Boolean value to convert. - /// - /// 1 if is - /// -or- - /// 0 otherwise. - /// + /// 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()); + /// 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)] public static ushort ToUInt16(this bool value) { - return value.ToByte(); + return value ? 1 : 0; } /// /// Converts the current Boolean value to the equivalent 32-bit unsigned integer. /// /// The Boolean value to convert. - /// - /// 1 if is - /// -or- - /// 0 otherwise. - /// + /// 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()); + /// 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)] public static uint ToUInt32(this bool value) { - return value.ToByte(); + return value ? 1U : 0U; } /// /// Converts the current Boolean value to the equivalent 64-bit unsigned integer. /// /// The Boolean value to convert. - /// - /// 1 if is - /// -or- - /// 0 otherwise. - /// + /// 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()); + /// 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)] public static ulong ToUInt64(this bool value) { - return value.ToByte(); + return value ? 1UL : 0UL; } } }