Skip to content

Instantly share code, notes, and snippets.

@ADIX7
Created July 3, 2019 13:43
Show Gist options
  • Save ADIX7/8de7d6663bbed39d943a7be575ee47d1 to your computer and use it in GitHub Desktop.
Save ADIX7/8de7d6663bbed39d943a7be575ee47d1 to your computer and use it in GitHub Desktop.
Extension method for bool to use if block as expression body
public static class IfExtensions
{
public static void IfTrue(this bool condition, Action action)
{
if(condition) action();
}
public static bool IfTrue(this bool condition, Func<bool> func)
{
if(condition) return func();
return condition;
}
public static void IfFalse(this bool condition, Action action)
{
if(!condition) action();
}
public static bool IfFalse(this bool condition, Func<bool> func)
{
if(!condition) return func();
return condition;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment