This project has moved. For the latest updates, please go here.

System.Boolean Extension Methods

Boolean.IfFalse Method

A bool extension method that execute an Action if the value is false.

Syntax

void IfFalse(bool @this,Action action)

Parameters

@this
The @this to act on.
action
The action to execute.

Examples


 // Copyright (c) 2013 Jonathan Magnan (http://zzzportal.com)
 // All rights reserved.
 // Licensed under MIT License (MIT)
 // License can be found here: https://zextensionmethods.codeplex.com/license
 
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Z;
 
 namespace ExtensionMethods.Examples
 {
     [TestClass]
     public class System_Boolean_IfFalse
     {
         [TestMethod]
         public void IfFalse()
         {
             string value1 = "";
             string value2 = "";
 
             // Type
             bool conditionTrue = true;
             bool conditionFalse = false;
 
             // Examples
             conditionTrue.IfFalse(() => value1 = "FizzBuzz"); // value1 = "";
             conditionFalse.IfFalse(() => value2 = "FizzBuzz"); // value2 = "FizzBuzz";
 
             // Unit Test
             Assert.AreEqual("", value1);
             Assert.AreEqual("FizzBuzz", value2);
         }
     }
 }
                

Boolean.IfTrue Method

A bool extension method that execute an Action if the value is true.

Syntax

void IfTrue(bool @this,Action action)

Parameters

@this
The @this to act on.
action
The action to execute.

Examples


 // Copyright (c) 2013 Jonathan Magnan (http://zzzportal.com)
 // All rights reserved.
 // Licensed under MIT License (MIT)
 // License can be found here: https://zextensionmethods.codeplex.com/license
 
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Z;
 
 namespace ExtensionMethods.Examples
 {
     [TestClass]
     public class System_Boolean_IfTrue
     {
         [TestMethod]
         public void IfTrue()
         {
             string value1 = "";
             string value2 = "";
 
             // Type
             bool conditionTrue = true;
             bool conditionFalse = false;
 
             // Examples
             conditionTrue.IfTrue(() => value1 = "FizzBuzz"); // value1 = "FizzBuzz";
             conditionFalse.IfTrue(() => value2 = "FizzBuzz"); // value2 = "";
 
             // Unit Test
             Assert.AreEqual("FizzBuzz", value1);
             Assert.AreEqual("", value2);
         }
     }
 }
                

Boolean.ToBinary Method

A bool extension method that convert this object into a binary representation. If the value is true then 1
otherwise 0.

Syntax

int ToBinary(bool @this)

Parameters

@this
The @this to act on.

Examples


 // Copyright (c) 2013 Jonathan Magnan (http://zzzportal.com)
 // All rights reserved.
 // Licensed under MIT License (MIT)
 // License can be found here: https://zextensionmethods.codeplex.com/license
 
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Z;
 
 namespace ExtensionMethods.Examples
 {
     [TestClass]
     public class System_Boolean_ToBinary
     {
         [TestMethod]
         public void ToBinary()
         {
             // Type
             bool conditionTrue = true;
             bool conditionFalse = false;
 
             // Examples
             int value1 = conditionTrue.ToBinary(); // return 1;
             int value2 = conditionFalse.ToBinary(); // return 0;
 
             // Unit Test
             Assert.AreEqual(1, value1);
             Assert.AreEqual(0, value2);
         }
     }
 }
                

Last edited Nov 23, 2013 at 7:48 PM by Jonathan_Magnan, version 1