Created
July 3, 2019 13:43
-
-
Save ADIX7/8de7d6663bbed39d943a7be575ee47d1 to your computer and use it in GitHub Desktop.
Extension method for bool to use if block as expression body
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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