Created
September 15, 2014 16:21
-
-
Save treefortress/1a9349d9e77e732f1c4a to your computer and use it in GitHub Desktop.
C# - Generic Action Dispatchers w/ Built-in null check
This file contains 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 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