Boolean - IfTrue

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

Try it

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

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

	// C# Extension Method: Boolean - IfTrue
    conditionTrue.IfTrue(() => value1 = "FizzBuzz");
    conditionFalse.IfTrue(() => 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 true.
    /// </summary>
    /// <param name="this">The @this to act on.</param>
    /// <param name="action">The action to execute.</param>
    public static void IfTrue(this bool @this, Action action)
    {
        if (@this)
        {
            action();
        }
    }
}