Skip to content

Instantly share code, notes, and snippets.

@treefortress
Created September 15, 2014 16:21
Show Gist options
  • Save treefortress/1a9349d9e77e732f1c4a to your computer and use it in GitHub Desktop.
Save treefortress/1a9349d9e77e732f1c4a to your computer and use it in GitHub Desktop.
C# - Generic Action Dispatchers w/ Built-in null check
public class ActionDispatcher {
protected void Dispatch(Action action) {
if (action != null) {
action();
}
}
protected void Dispatch<T0>(Action<T0> action, T0 param0) {
if (action != null) {
action(param0);
}
}
protected void Dispatch<T0, T1>(Action<T0, T1> action, T0 param0, T1 param1) {
if (action != null) {
action(param0, param1);
}
}
protected void Dispatch<T0, T1, T2>(Action<T0, T1, T2> action, T0 param0, T1 param1, T2 param2) {
if (action != null) {
action(param0, param1, param2);
}
}
protected void Dispatch<T0, T1, T2, T3>(Action<T0, T1, T2, T3> action, T0 param0, T1 param1, T2 param2, T3 param3) {
if (action != null) {
action(param0, param1, param2, param3);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment