Skip to content

Instantly share code, notes, and snippets.

@PopupAsylumUK
Created May 2, 2018 15:55
Show Gist options
  • Save PopupAsylumUK/aa367ac6f5f883a698f5d04f1faf9b07 to your computer and use it in GitHub Desktop.
Save PopupAsylumUK/aa367ac6f5f883a698f5d04f1faf9b07 to your computer and use it in GitHub Desktop.
Adds null checking invocations to Actions
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