I think you want:
public static Action<Tuple<T1,T2>> CombineWith<T1,T2> (this Action<T1> action1, Action<T2> action2) {
Using:
Action<int> a1 = x => Console.Write(x + 1); Action<string> a2 = x => Console.Write(" " + x + " a week"); var combined = a1.CombineWith(a2);
EDIT : By the way, I noticed that you mentioned in a comment that "accepting arguments individually would be even more preferable." In this case, you can:
public static Action<T1, T2> CombineWith<T1, T2> (this Action<T1> action1, Action<T2> action2) { //null-checks here. return (x, y) => { action1(x); action2(y); }; }
Ani
source share