1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-23 00:58:48 +00:00

🔧 Consolidate methods into sensible partials

This commit is contained in:
Oliver Booth 2021-01-17 12:48:19 +00:00
parent 17f6a05c48
commit 96f68343ce
12 changed files with 349 additions and 190 deletions

View File

@ -0,0 +1,132 @@
using System;
using System.Runtime.CompilerServices;
namespace X10D.BooleanExtensions
{
public static partial class BooleanExtensions
{
/// <summary>
/// Converts the current Boolean value to the equivalent 8-bit signed integer.
/// </summary>
/// <param name="value">The Boolean value to convert.</param>
/// <returns>
/// <c>1</c> if <paramref name="value" /> is <see langword="false" />
/// -or-
/// <c>0</c> otherwise.
/// </returns>
/// <example>
/// The following example illustrates the conversion of <see cref="bool" /> to <see cref="sbyte" /> values.
/// <code lang="csharp">
/// 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.
/// </code>
/// </example>
[CLSCompliant(false)]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static sbyte ToSByte(this bool value)
{
return value ? 1 : 0;
}
/// <summary>
/// Converts the current Boolean value to the equivalent 16-bit unsigned integer.
/// </summary>
/// <param name="value">The Boolean value to convert.</param>
/// <returns>
/// <c>1</c> if <paramref name="value" /> is <see langword="false" />
/// -or-
/// <c>0</c> otherwise.
/// </returns>
/// <example>
/// The following example illustrates the conversion of <see cref="bool" /> to <see cref="ushort" /> values.
/// <code lang="csharp">
/// 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.
/// </code>
/// </example>
[CLSCompliant(false)]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ushort ToUInt16(this bool value)
{
return value.ToByte();
}
/// <summary>
/// Converts the current Boolean value to the equivalent 32-bit unsigned integer.
/// </summary>
/// <param name="value">The Boolean value to convert.</param>
/// <returns>
/// <c>1</c> if <paramref name="value" /> is <see langword="false" />
/// -or-
/// <c>0</c> otherwise.
/// </returns>
/// <example>
/// The following example illustrates the conversion of <see cref="bool" /> to <see cref="uint" /> values.
/// <code lang="csharp">
/// 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.
/// </code>
/// </example>
[CLSCompliant(false)]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint ToUInt32(this bool value)
{
return value.ToByte();
}
/// <summary>
/// Converts the current Boolean value to the equivalent 64-bit unsigned integer.
/// </summary>
/// <param name="value">The Boolean value to convert.</param>
/// <returns>
/// <c>1</c> if <paramref name="value" /> is <see langword="false" />
/// -or-
/// <c>0</c> otherwise.
/// </returns>
/// <example>
/// The following example illustrates the conversion of <see cref="bool" /> to <see cref="ulong" /> values.
/// <code lang="csharp">
/// 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.
/// </code>
/// </example>
[CLSCompliant(false)]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ulong ToUInt64(this bool value)
{
return value.ToByte();
}
}
}

View File

@ -0,0 +1,217 @@
using System.Runtime.CompilerServices;
namespace X10D.BooleanExtensions
{
public static partial class BooleanExtensions
{
/// <summary>
/// Converts the current Boolean value to the equivalent 8-bit unsigned integer.
/// </summary>
/// <param name="value">The Boolean value to convert.</param>
/// <returns>
/// <c>1</c> if <paramref name="value" /> is <see langword="false" />
/// -or-
/// <c>0</c> 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>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static byte ToByte(this bool value)
{
return 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>
/// <c>1</c> if <paramref name="value" /> is <see langword="false" />
/// -or-
/// <c>0</c> 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.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>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static decimal ToDecimal(this bool value)
{
return value.ToByte();
}
/// <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>
/// <c>1</c> if <paramref name="value" /> is <see langword="false" />
/// -or-
/// <c>0</c> otherwise.
/// </returns>
/// <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>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static long ToDouble(this bool value)
{
return value.ToByte();
}
/// <summary>
/// Converts the current Boolean value to the equivalent 16-bit signed integer.
/// </summary>
/// <param name="value">The Boolean value to convert.</param>
/// <returns>
/// <c>1</c> if <paramref name="value" /> is <see langword="false" />
/// -or-
/// <c>0</c> 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>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static short ToInt16(this bool value)
{
return value.ToByte();
}
/// <summary>
/// Converts the current Boolean value to the equivalent 32-bit signed integer.
/// </summary>
/// <param name="value">The Boolean value to convert.</param>
/// <returns>
/// <c>1</c> if <paramref name="value" /> is <see langword="false" />
/// -or-
/// <c>0</c> 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>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int ToInt32(this bool value)
{
return value.ToByte();
}
/// <summary>
/// Converts the current Boolean value to the equivalent 64-bit signed integer.
/// </summary>
/// <param name="value">The Boolean value to convert.</param>
/// <returns>
/// <c>1</c> if <paramref name="value" /> is <see langword="false" />
/// -or-
/// <c>0</c> 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>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static long ToInt64(this bool value)
{
return value.ToByte();
}
/// <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>
/// <c>1</c> if <paramref name="value" /> is <see langword="false" />
/// -or-
/// <c>0</c> 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>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float ToSingle(this bool value)
{
return value.ToByte();
}
}
}

View File

@ -1,19 +0,0 @@
namespace X10D.BooleanExtensions
{
public static partial class BooleanExtensions
{
/// <summary>
/// Converts the current <see cref="bool" /> to a 1-byte unsigned integer representing its truthiness.
/// </summary>
/// <param name="value">The value to convert.</param>
/// <returns>
/// <c>1</c> if <paramref name="value" /> is <see langword="true"/>
/// -or-
/// <c>0</c> otherwise.
/// </returns>
public static byte ToByte(this bool value)
{
return value ? 1 : 0;
}
}
}

View File

@ -1,19 +0,0 @@
namespace X10D.BooleanExtensions
{
public static partial class BooleanExtensions
{
/// <summary>
/// Converts the current <see cref="bool" /> to a decimal floating-point number representing its truthiness.
/// </summary>
/// <param name="value">The value to convert.</param>
/// <returns>
/// <c>1</c> if <paramref name="value" /> is <see langword="true"/>
/// -or-
/// <c>0</c> otherwise.
/// </returns>
public static decimal ToDecimal(this bool value)
{
return value.ToByte();
}
}
}

View File

@ -1,19 +0,0 @@
namespace X10D.BooleanExtensions
{
public static partial class BooleanExtensions
{
/// <summary>
/// Converts the current <see cref="bool" /> to a double-precision floating-point number representing its truthiness.
/// </summary>
/// <param name="value">The value to convert.</param>
/// <returns>
/// <c>1</c> if <paramref name="value" /> is <see langword="true"/>
/// -or-
/// <c>0</c> otherwise.
/// </returns>
public static long ToDouble(this bool value)
{
return value.ToByte();
}
}
}

View File

@ -1,19 +0,0 @@
namespace X10D.BooleanExtensions
{
public static partial class BooleanExtensions
{
/// <summary>
/// Converts the current <see cref="bool" /> to a 2-byte signed integer representing its truthiness.
/// </summary>
/// <param name="value">The value to convert.</param>
/// <returns>
/// <c>1</c> if <paramref name="value" /> is <see langword="true"/>
/// -or-
/// <c>0</c> otherwise.
/// </returns>
public static short ToInt16(this bool value)
{
return value.ToByte();
}
}
}

View File

@ -1,19 +0,0 @@
namespace X10D.BooleanExtensions
{
public static partial class BooleanExtensions
{
/// <summary>
/// Converts the current <see cref="bool" /> to a 4-byte signed integer representing its truthiness.
/// </summary>
/// <param name="value">The value to convert.</param>
/// <returns>
/// <c>1</c> if <paramref name="value" /> is <see langword="true"/>
/// -or-
/// <c>0</c> otherwise.
/// </returns>
public static int ToInt32(this bool value)
{
return value.ToByte();
}
}
}

View File

@ -1,19 +0,0 @@
namespace X10D.BooleanExtensions
{
public static partial class BooleanExtensions
{
/// <summary>
/// Converts the current <see cref="bool" /> to an 8-byte signed integer representing its truthiness.
/// </summary>
/// <param name="value">The value to convert.</param>
/// <returns>
/// <c>1</c> if <paramref name="value" /> is <see langword="true"/>
/// -or-
/// <c>0</c> otherwise.
/// </returns>
public static long ToInt64(this bool value)
{
return value.ToByte();
}
}
}

View File

@ -1,19 +0,0 @@
namespace X10D.BooleanExtensions
{
public static partial class BooleanExtensions
{
/// <summary>
/// Converts the current <see cref="bool" /> to a single-precision floating-point number representing its truthiness.
/// </summary>
/// <param name="value">The value to convert.</param>
/// <returns>
/// <c>1</c> if <paramref name="value" /> is <see langword="true"/>
/// -or-
/// <c>0</c> otherwise.
/// </returns>
public static float ToSingle(this bool value)
{
return value.ToByte();
}
}
}

View File

@ -1,19 +0,0 @@
namespace X10D.BooleanExtensions
{
public static partial class BooleanExtensions
{
/// <summary>
/// Converts the current <see cref="bool" /> to a 2-byte unsigned integer representing its truthiness.
/// </summary>
/// <param name="value">The value to convert.</param>
/// <returns>
/// <c>1</c> if <paramref name="value" /> is <see langword="true"/>
/// -or-
/// <c>0</c> otherwise.
/// </returns>
public static ushort ToUInt16(this bool value)
{
return value.ToByte();
}
}
}

View File

@ -1,19 +0,0 @@
namespace X10D.BooleanExtensions
{
public static partial class BooleanExtensions
{
/// <summary>
/// Converts the current <see cref="bool" /> to a 4-byte unsigned integer representing its truthiness.
/// </summary>
/// <param name="value">The value to convert.</param>
/// <returns>
/// <c>1</c> if <paramref name="value" /> is <see langword="true"/>
/// -or-
/// <c>0</c> otherwise.
/// </returns>
public static uint ToUInt32(this bool value)
{
return value.ToByte();
}
}
}

View File

@ -1,19 +0,0 @@
namespace X10D.BooleanExtensions
{
public static partial class BooleanExtensions
{
/// <summary>
/// Converts the current <see cref="bool" /> to an 8-byte unsigned integer representing its truthiness.
/// </summary>
/// <param name="value">The value to convert.</param>
/// <returns>
/// <c>1</c> if <paramref name="value" /> is <see langword="true"/>
/// -or-
/// <c>0</c> otherwise.
/// </returns>
public static ulong ToUInt64(this bool value)
{
return value.ToByte();
}
}
}