1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-10 04:55:42 +00:00

Remove To/From boolean methods

Consumers should cast to IConvertible and call already-existing method
This commit is contained in:
Oliver Booth 2022-02-14 15:52:03 +00:00
parent a8087771c8
commit 7c05af1fde
8 changed files with 5 additions and 295 deletions

View File

@ -33,174 +33,5 @@
{
return BitConverter.GetBytes(value);
}
/// <summary>
/// Converts the current Boolean value to the equivalent 8-bit unsigned integer.
/// </summary>
/// <param name="value">The Boolean value to convert.</param>
/// <returns>1 if <paramref name="value" /> is <see langword="false" />, or 0 otherwise.</returns>
/// <example>
/// The following example illustrates the conversion of <see cref="bool" /> to <see cref="byte" /> values.
/// <code lang="csharp">
/// 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.
/// </code>
/// </example>
/// <seealso cref="ByteExtensions.ToBoolean(byte)" />
public static byte ToByte(this bool value)
{
return (byte)(value ? 1 : 0);
}
/// <summary>
/// Converts the current Boolean value to the equivalent decimal number.
/// </summary>
/// <param name="value">The Boolean value to convert.</param>
/// <returns>1 if <paramref name="value" /> is <see langword="false" />, or 0 otherwise.</returns>
/// <example>
/// The following example illustrates the conversion of <see cref="bool" /> to <see cref="decimal" /> values.
/// <code lang="csharp">
/// 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.
/// </code>
/// </example>
/// <seealso cref="DecimalExtensions.ToBoolean(decimal)" />
public static decimal ToDecimal(this bool value)
{
return value ? 1.0m : 0.0m;
}
/// <summary>
/// Converts the current Boolean value to the equivalent double-precision floating-point number.
/// </summary>
/// <param name="value">The Boolean value to convert.</param>
/// <returns>1 if <paramref name="value" /> is <see langword="false" />, or 0 otherwise.</returns>
/// <seealso cref="DoubleExtensions.ToBoolean(double)" />
/// <example>
/// The following example illustrates the conversion of <see cref="bool" /> to <see cref="double" /> values.
/// <code lang="csharp">
/// 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.
/// </code>
/// </example>
/// <seealso cref="DoubleExtensions.ToBoolean(double)" />
public static double ToDouble(this bool value)
{
return value ? 1.0 : 0.0;
}
/// <summary>
/// Converts the current Boolean value to the equivalent 16-bit signed integer.
/// </summary>
/// <param name="value">The Boolean value to convert.</param>
/// <returns>1 if <paramref name="value" /> is <see langword="false" />, or 0 otherwise.</returns>
/// <example>
/// The following example illustrates the conversion of <see cref="bool" /> to <see cref="short" /> values.
/// <code lang="csharp">
/// 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.
/// </code>
/// </example>
/// <seealso cref="Int16Extensions.ToBoolean(short)" />
public static short ToInt16(this bool value)
{
return (short)(value ? 1 : 0);
}
/// <summary>
/// Converts the current Boolean value to the equivalent 32-bit signed integer.
/// </summary>
/// <param name="value">The Boolean value to convert.</param>
/// <returns>1 if <paramref name="value" /> is <see langword="false" />, or 0 otherwise.</returns>
/// <example>
/// The following example illustrates the conversion of <see cref="bool" /> to <see cref="int" /> values.
/// <code lang="csharp">
/// 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.
/// </code>
/// </example>
/// <seealso cref="Int32Extensions.ToBoolean(int)" />
public static int ToInt32(this bool value)
{
return value ? 1 : 0;
}
/// <summary>
/// Converts the current Boolean value to the equivalent 64-bit signed integer.
/// </summary>
/// <param name="value">The Boolean value to convert.</param>
/// <returns>1 if <paramref name="value" /> is <see langword="false" />, or 0 otherwise.</returns>
/// <example>
/// The following example illustrates the conversion of <see cref="bool" /> to <see cref="long" /> values.
/// <code lang="csharp">
/// 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.
/// </code>
/// </example>
/// <seealso cref="Int64Extensions.ToBoolean(long)" />
public static long ToInt64(this bool value)
{
return value ? 1L : 0L;
}
/// <summary>
/// Converts the current Boolean value to the equivalent single-precision floating-point number.
/// </summary>
/// <param name="value">The Boolean value to convert.</param>
/// <returns>1 if <paramref name="value" /> is <see langword="false" />, or 0 otherwise.</returns>
/// <example>
/// The following example illustrates the conversion of <see cref="bool" /> to <see cref="float" /> values.
/// <code lang="csharp">
/// 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.
/// </code>
/// </example>
/// <seealso cref="SingleExtensions.ToBoolean(float)" />
public static float ToSingle(this bool value)
{
return value ? 1.0f : 0.0f;
}
}
}

View File

@ -1,4 +1,4 @@
namespace X10D
namespace X10D
{
/// <summary>
/// Extension methods for <see cref="byte" />.
@ -52,37 +52,5 @@ namespace X10D
{
return ((short)value).IsPrime();
}
/// <summary>
/// Converts the value of the current 8-bit unsigned integer to an equivalent Boolean value.
/// </summary>
/// <param name="value">The 8-bit unsigned integer to convert.</param>
/// <returns>
/// <see langword="true" /> if <paramref name="value" /> is not zero, or <see langword="false" /> otherwise.
/// </returns>
/// <seealso cref="BooleanExtensions.ToByte(bool)" />
/// <example>
/// The following example converts an array of <see cref="byte" /> values to <see cref="bool" /> values.
/// <code lang="csharp">
/// 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
/// </code>
/// </example>
public static bool ToBoolean(this byte value)
{
return value != 0;
}
}
}

View File

@ -45,38 +45,5 @@ namespace X10D
{
return ((short)value).IsPrime();
}
/// <summary>
/// Converts the value of the current 8-bit signed integer to an equivalent Boolean value.
/// </summary>
/// <param name="value">The 8-bit signed integer to convert.</param>
/// <returns>
/// <see langword="true" /> if <paramref name="value" /> is not zero, or <see langword="false" /> otherwise.
/// </returns>
/// <seealso cref="BooleanExtensions.BooleanExtensions.ToByte(bool)" />
/// <example>
/// The following example converts an array of <see cref="byte" /> values to <see cref="bool" /> values.
///
/// <code lang="csharp">
/// 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
/// </code>
/// </example>
public static bool ToBoolean(this sbyte value)
{
return value != 0;
}
}
}

View File

@ -1,4 +1,4 @@
namespace X10D
namespace X10D
{
/// <summary>
/// Extension methods for <see cref="double" />.
@ -123,17 +123,5 @@ namespace X10D
{
return Math.Round(value / nearest) * nearest;
}
/// <summary>
/// Converts the value of the current double-precision floating-point number to an equivalent Boolean value.
/// </summary>
/// <param name="value">The value to convert.</param>
/// <returns>
/// <see langword="true" /> if <paramref name="value" /> is not zero, or <see langword="false" /> otherwise.
/// </returns>
public static bool ToBoolean(this double value)
{
return value != 0.0;
}
}
}

View File

@ -1,4 +1,4 @@
using System.Net;
using System.Net;
namespace X10D
{
@ -177,16 +177,6 @@ namespace X10D
return MathUtils.Lerp(value, target, alpha);
}
/// <summary>
/// Converts the value of the current 16-bit signed integer to an equivalent <see cref="bool" /> value.
/// </summary>
/// <param name="value">The value to convert.</param>
/// <returns><see langword="true" /> if <paramref name="value" /> is not zero, or <see langword="false" /> otherwise.</returns>
public static bool ToBoolean(this short value)
{
return value != 0;
}
/// <summary>
/// Converts an integer value from network byte order to host byte order.
/// </summary>

View File

@ -241,16 +241,6 @@ namespace X10D
return r < 0 ? r + divisor : r;
}
/// <summary>
/// Converts the value of the current 32-bit signed integer to an equivalent <see cref="bool" /> value.
/// </summary>
/// <param name="value">The value to convert.</param>
/// <returns><see langword="true" /> if <paramref name="value" /> is not zero, or <see langword="false" /> otherwise.</returns>
public static bool ToBoolean(this int value)
{
return value != 0;
}
/// <summary>
/// Converts an integer value from network byte order to host byte order.
/// </summary>

View File

@ -1,4 +1,4 @@
using System.Net;
using System.Net;
namespace X10D
{
@ -202,18 +202,6 @@ namespace X10D
return MathUtils.Lerp(value, target, alpha);
}
/// <summary>
/// Converts the value of the current 64-bit signed integer to an equivalent Boolean value.
/// </summary>
/// <param name="value">The value to convert.</param>
/// <returns>
/// <see langword="true" /> if <paramref name="value" /> is not zero, or <see langword="false" /> otherwise.
/// </returns>
public static bool ToBoolean(this long value)
{
return value != 0;
}
/// <summary>
/// Converts an integer value from network byte order to host byte order.
/// </summary>

View File

@ -1,4 +1,4 @@
namespace X10D
namespace X10D
{
/// <summary>
/// Extension methods for <see cref="float" />.
@ -123,17 +123,5 @@ namespace X10D
{
return (float)((double)value).Round(nearest);
}
/// <summary>
/// Converts the value of the current single-precision floating-point number to an equivalent Boolean value.
/// </summary>
/// <param name="value">The value to convert.</param>
/// <returns>
/// <see langword="true" /> if <paramref name="value" /> is not zero, or <see langword="false" /> otherwise.
/// </returns>
public static bool ToBoolean(this float value)
{
return value != 0.0f;
}
}
}