In this line:
d_Lines = new FuncInvoker(i_FuncToAdd);
... you are actually creating a new delegate instance that wraps the original delegate. The target method of this new delegate will be the Invoke method of the original delegate (assuming it is unicast), which explains the behavior you observe.
The obvious workaround is not to use the shell and just copy the reference to the original delegate to the variable:
d_Lines = i_FuncToAdd;
But you can also completely abandon your "special case" branch and just do it (if the argument cannot be null ):
public void AddMenuRow(FuncInvoker i_FuncToAdd) { d_Lines += i_FuncToAdd; }
This will work just fine since Delegate.Combine (this is what the syntax += means) to return a link to the second delegate if the first delegate is null rather than throwing an exception.
source share