Boolean - IfFalse

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

Try it

public static void Main()
{
	string value1 = "";
    string value2 = "";

    const bool conditionTrue = true;
    const bool conditionFalse = false;

	// C# Extension Method: Boolean - IfFalse
    conditionTrue.IfFalse(() => value1 = "FizzBuzz");
    conditionFalse.IfFalse(() => value2 = "FizzBuzz");
	
	Console.WriteLine("value1 = {0}", value1);
	Console.WriteLine("value2 = {0}", value2);
}

View Source
using System;

public static partial class Extensions
{
    /// <summary>
    ///     A bool extension method that execute an Action if the value is false.
    /// </summary>
    /// <param name="this">The @this to act on.</param>
    /// <param name="action">The action to execute.</param>
    public static void IfFalse(this bool @this, Action action)
    {
        if (!@this)
        {
            action();
        }
    }
}