From 7c05af1fdefccd605e7d31eab2445886113f3723 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Mon, 14 Feb 2022 15:52:03 +0000 Subject: [PATCH] Remove To/From boolean methods Consumers should cast to IConvertible and call already-existing method --- .../BooleanExtensions/BooleanExtensions.cs | 169 ------------------ X10D/src/ByteExtensions/ByteExtensions.cs | 34 +--- X10D/src/ByteExtensions/SByteExtensions.cs | 33 ---- X10D/src/DoubleExtensions/DoubleExtensions.cs | 14 +- X10D/src/Int16Extensions/Int16Extensions.cs | 12 +- X10D/src/Int32Extensions/Int32Extensions.cs | 10 -- X10D/src/Int64Extensions/Int64Extensions.cs | 14 +- X10D/src/SingleExtensions/SingleExtensions.cs | 14 +- 8 files changed, 5 insertions(+), 295 deletions(-) diff --git a/X10D/src/BooleanExtensions/BooleanExtensions.cs b/X10D/src/BooleanExtensions/BooleanExtensions.cs index 71710e5..c4df71b 100644 --- a/X10D/src/BooleanExtensions/BooleanExtensions.cs +++ b/X10D/src/BooleanExtensions/BooleanExtensions.cs @@ -33,174 +33,5 @@ { return BitConverter.GetBytes(value); } - - /// - /// 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. - /// - /// - /// - public static byte ToByte(this bool value) - { - return (byte)(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.ToDecimal()); - /// Console.WriteLine("{0} converts to {1}.", trueFlag, trueFlag.ToDecimal()); - /// // The example displays the following output: - /// // False converts to 0. - /// // True converts to 1. - /// - /// - /// - public static decimal ToDecimal(this bool value) - { - return value ? 1.0m : 0.0m; - } - - /// - /// 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. - /// - /// - /// - public static double ToDouble(this bool value) - { - return value ? 1.0 : 0.0; - } - - /// - /// 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. - /// - /// - /// - public static short ToInt16(this bool value) - { - return (short)(value ? 1 : 0); - } - - /// - /// 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. - /// - /// - /// - public static int ToInt32(this bool value) - { - return value ? 1 : 0; - } - - /// - /// 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. - /// - /// - /// - public static long ToInt64(this bool value) - { - return value ? 1L : 0L; - } - - /// - /// 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. - /// - /// - /// - public static float ToSingle(this bool value) - { - return value ? 1.0f : 0.0f; - } } } diff --git a/X10D/src/ByteExtensions/ByteExtensions.cs b/X10D/src/ByteExtensions/ByteExtensions.cs index 60c0c4f..6bf8343 100644 --- a/X10D/src/ByteExtensions/ByteExtensions.cs +++ b/X10D/src/ByteExtensions/ByteExtensions.cs @@ -1,4 +1,4 @@ -namespace X10D +namespace X10D { /// /// Extension methods for . @@ -52,37 +52,5 @@ namespace X10D { return ((short)value).IsPrime(); } - - /// - /// Converts the value of the current 8-bit unsigned integer to an equivalent Boolean value. - /// - /// The 8-bit unsigned integer to convert. - /// - /// if is not zero, or otherwise. - /// - /// - /// - /// The following example converts an array of values to values. - /// - /// byte[] bytes = { byte.MinValue, 100, 200, byte.MaxValue }; - /// bool result; - /// - /// foreach (byte value in bytes) - /// { - /// result = value.ToBoolean(); - /// Console.WriteLine("{0, -5} --> {1}", value, result); - /// } - /// - /// // The example displays the following output: - /// // 0 --> False - /// // 100 --> True - /// // 200 --> True - /// // 255 --> True - /// - /// - public static bool ToBoolean(this byte value) - { - return value != 0; - } } } diff --git a/X10D/src/ByteExtensions/SByteExtensions.cs b/X10D/src/ByteExtensions/SByteExtensions.cs index aeeb471..0037249 100644 --- a/X10D/src/ByteExtensions/SByteExtensions.cs +++ b/X10D/src/ByteExtensions/SByteExtensions.cs @@ -45,38 +45,5 @@ namespace X10D { return ((short)value).IsPrime(); } - - /// - /// Converts the value of the current 8-bit signed integer to an equivalent Boolean value. - /// - /// The 8-bit signed integer to convert. - /// - /// if is not zero, or otherwise. - /// - /// - /// - /// The following example converts an array of values to values. - /// - /// - /// byte[] bytes = { byte.MinValue, 100, 200, byte.MaxValue }; - /// bool result; - /// - /// foreach (byte value in bytes) - /// { - /// result = value.ToBoolean(); - /// Console.WriteLine("{0, -5} --> {1}", value, result); - /// } - /// - /// // The example displays the following output: - /// // 0 --> False - /// // 100 --> True - /// // 200 --> True - /// // 255 --> True - /// - /// - public static bool ToBoolean(this sbyte value) - { - return value != 0; - } } } diff --git a/X10D/src/DoubleExtensions/DoubleExtensions.cs b/X10D/src/DoubleExtensions/DoubleExtensions.cs index 6c998d4..425ec0f 100644 --- a/X10D/src/DoubleExtensions/DoubleExtensions.cs +++ b/X10D/src/DoubleExtensions/DoubleExtensions.cs @@ -1,4 +1,4 @@ -namespace X10D +namespace X10D { /// /// Extension methods for . @@ -123,17 +123,5 @@ namespace X10D { return Math.Round(value / nearest) * nearest; } - - /// - /// Converts the value of the current double-precision floating-point number to an equivalent Boolean value. - /// - /// The value to convert. - /// - /// if is not zero, or otherwise. - /// - public static bool ToBoolean(this double value) - { - return value != 0.0; - } } } diff --git a/X10D/src/Int16Extensions/Int16Extensions.cs b/X10D/src/Int16Extensions/Int16Extensions.cs index 36c7381..b334c3f 100644 --- a/X10D/src/Int16Extensions/Int16Extensions.cs +++ b/X10D/src/Int16Extensions/Int16Extensions.cs @@ -1,4 +1,4 @@ -using System.Net; +using System.Net; namespace X10D { @@ -177,16 +177,6 @@ namespace X10D return MathUtils.Lerp(value, target, alpha); } - /// - /// 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; - } - /// /// Converts an integer value from network byte order to host byte order. /// diff --git a/X10D/src/Int32Extensions/Int32Extensions.cs b/X10D/src/Int32Extensions/Int32Extensions.cs index 5d82bc5..0bd1ece 100644 --- a/X10D/src/Int32Extensions/Int32Extensions.cs +++ b/X10D/src/Int32Extensions/Int32Extensions.cs @@ -241,16 +241,6 @@ namespace X10D return r < 0 ? r + divisor : r; } - /// - /// 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; - } - /// /// Converts an integer value from network byte order to host byte order. /// diff --git a/X10D/src/Int64Extensions/Int64Extensions.cs b/X10D/src/Int64Extensions/Int64Extensions.cs index d4ba521..37a2632 100644 --- a/X10D/src/Int64Extensions/Int64Extensions.cs +++ b/X10D/src/Int64Extensions/Int64Extensions.cs @@ -1,4 +1,4 @@ -using System.Net; +using System.Net; namespace X10D { @@ -202,18 +202,6 @@ namespace X10D return MathUtils.Lerp(value, target, alpha); } - /// - /// Converts the value of the current 64-bit signed integer to an equivalent Boolean value. - /// - /// The value to convert. - /// - /// if is not zero, or otherwise. - /// - public static bool ToBoolean(this long value) - { - return value != 0; - } - /// /// Converts an integer value from network byte order to host byte order. /// diff --git a/X10D/src/SingleExtensions/SingleExtensions.cs b/X10D/src/SingleExtensions/SingleExtensions.cs index a61e2a6..2408946 100644 --- a/X10D/src/SingleExtensions/SingleExtensions.cs +++ b/X10D/src/SingleExtensions/SingleExtensions.cs @@ -1,4 +1,4 @@ -namespace X10D +namespace X10D { /// /// Extension methods for . @@ -123,17 +123,5 @@ namespace X10D { return (float)((double)value).Round(nearest); } - - /// - /// Converts the value of the current single-precision floating-point number to an equivalent Boolean value. - /// - /// The value to convert. - /// - /// if is not zero, or otherwise. - /// - public static bool ToBoolean(this float value) - { - return value != 0.0f; - } } }