Skip to content

Instantly share code, notes, and snippets.

@emrahyumuk
Last active January 11, 2017 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emrahyumuk/053dd20e249b9cc887811508fc177dab to your computer and use it in GitHub Desktop.
Save emrahyumuk/053dd20e249b9cc887811508fc177dab to your computer and use it in GitHub Desktop.
Run Actions with n parameters
public static void Main()
{
Invoke<List<string>>(Test1, new List<string>());
Invoke<string, int>(Test2, string.Empty, 1);
Invoke<string, int, object>(Test3, string.Empty, 1, null);
}
private static void Invoke<T1>(Action<T1> a, T1 p)
{
InvokeMyMethod(a, p);
}
private static void Invoke<T1, T2>(Action<T1, T2> a, T1 p1, T2 p2 )
{
InvokeMyMethod(a, p1, p2);
}
private static void Invoke<T1, T2, T3>(Action<T1, T2, T3> a, T1 p1, T2 p2, T3 p3)
{
InvokeMyMethod(a, p1, p2, p3);
}
private static void InvokeMyMethod(Delegate method, params object[] args)
{
method.DynamicInvoke(args);
}
public static void Test1(List<string> t)
{
}
public static void Test2(string t1, int t2)
{
}
public static void Test3(string t1, int t2, object t3)
{
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment