Created
May 2, 2018 15:55
-
-
Save PopupAsylumUK/aa367ac6f5f883a698f5d04f1faf9b07 to your computer and use it in GitHub Desktop.
Adds null checking invocations to Actions
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
using System; | |
public static class ActionExtensions { | |
public static void SafeInvoke(this Action action) { | |
if (action != null) { | |
action(); | |
} | |
} | |
public static void SafeInvoke<T>(this Action<T> action, T value) { | |
if (action != null) { | |
action(value); | |
} | |
} | |
public static void SafeInvoke<T, U>(this Action<T, U> action, T value0, U value1) { | |
if (action != null) { | |
action(value0, value1); | |
} | |
} | |
public static void SafeInvoke<T, U, V>(this Action<T, U, V> action, T value0, U value1, V value2) { | |
if (action != null) { | |
action(value0, value1, value2); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment