From e537b9c727249ab1699710fe8957623669f72ac8 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Sat, 16 Nov 2019 01:53:16 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20ToBoolean()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ToBoolean() returns false if value is 0, true otherwise --- X10D/Int16Extensions.cs | 18 ++++++++++++++++++ X10D/Int32Extensions.cs | 18 ++++++++++++++++++ X10D/Int64Extensions.cs | 18 ++++++++++++++++++ 3 files changed, 54 insertions(+) diff --git a/X10D/Int16Extensions.cs b/X10D/Int16Extensions.cs index 5e8d0fb..f37949c 100644 --- a/X10D/Int16Extensions.cs +++ b/X10D/Int16Extensions.cs @@ -112,5 +112,23 @@ /// otherwise. public static bool IsPrime(this short number) => ((long) number).IsPrime(); + + /// + /// Gets an boolean value that represents this integer. + /// + /// The integer. + /// Returns if is 0, + /// otherwise. + public static bool ToBoolean(this short value) => + value != 0; + + /// + /// Gets an boolean value that represents this integer. + /// + /// The integer. + /// Returns if is 0, + /// otherwise. + public static bool ToBoolean(this ushort value) => + value != 0; } } \ No newline at end of file diff --git a/X10D/Int32Extensions.cs b/X10D/Int32Extensions.cs index 8f03a5d..055aad7 100644 --- a/X10D/Int32Extensions.cs +++ b/X10D/Int32Extensions.cs @@ -111,5 +111,23 @@ /// otherwise. public static bool IsPrime(this int number) => ((long)number).IsPrime(); + + /// + /// Gets an boolean value that represents this integer. + /// + /// The integer. + /// Returns if is 0, + /// otherwise. + public static bool ToBoolean(this int value) => + value != 0; + + /// + /// Gets an boolean value that represents this integer. + /// + /// The integer. + /// Returns if is 0, + /// otherwise. + public static bool ToBoolean(this uint value) => + value != 0; } } diff --git a/X10D/Int64Extensions.cs b/X10D/Int64Extensions.cs index 84d6284..ccab490 100644 --- a/X10D/Int64Extensions.cs +++ b/X10D/Int64Extensions.cs @@ -134,5 +134,23 @@ return true; } + + /// + /// Gets an boolean value that represents this integer. + /// + /// The integer. + /// Returns if is 0, + /// otherwise. + public static bool ToBoolean(this long value) => + value != 0; + + /// + /// Gets an boolean value that represents this integer. + /// + /// The integer. + /// Returns if is 0, + /// otherwise. + public static bool ToBoolean(this ulong value) => + value != 0; } }