Add ToInt16 and ToInt64 in BooleanExtensions

This commit is contained in:
Oliver Booth 2020-04-18 23:38:33 +01:00
parent 6be765a92d
commit 66d68b01bf
No known key found for this signature in database
GPG Key ID: 0D7F2EF1C8D2B9C0
1 changed files with 26 additions and 6 deletions

View File

@ -65,23 +65,43 @@
}
/// <summary>
/// Gets an integer value that represents this boolean.
/// Gets the value of this boolean as represented by <see cref="byte"/>.
/// </summary>
/// <param name="value">The boolean.</param>
/// <returns>Returns 1 if <paramref name="value"/> is <see langword="true"/>, 0 otherwise.</returns>
/// <returns>Returns 1 if <paramref name="value"/> is <see langword="true"/>, or 0 otherwise.</returns>
public static byte ToByte(this bool value)
{
return (byte)value.ToInt32();
}
/// <summary>
/// Gets the value of this boolean as represented by <see cref="short"/>.
/// </summary>
/// <param name="value">The boolean.</param>
/// <returns>Returns 1 if <paramref name="value"/> is <see langword="true"/>, or 0 otherwise.</returns>
public static short ToInt16(this bool value)
{
return (short)value.ToInt32();
}
/// <summary>
/// Gets the value of this boolean as represented by <see cref="int"/>.
/// </summary>
/// <param name="value">The boolean.</param>
/// <returns>Returns 1 if <paramref name="value"/> is <see langword="true"/>, or 0 otherwise.</returns>
public static int ToInt32(this bool value)
{
return value ? 1 : 0;
}
/// <summary>
/// Gets a byte value that represents this boolean.
/// Gets the value of this boolean as represented by <see cref="long"/>.
/// </summary>
/// <param name="value">The boolean.</param>
/// <returns>Returns 00000001 if <paramref name="value"/> is <see langword="true"/>, otherwise 0000000.</returns>
public static byte ToByte(this bool value)
/// <returns>Returns 1 if <paramref name="value"/> is <see langword="true"/>, 0 otherwise.</returns>
public static long ToInt64(this bool value)
{
return (byte)(value ? 1 : 0);
return value.ToInt32();
}
/// <summary>