Reputation: 13106
I recently saw some code like this (which is calling a delegate):
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
Debug.WriteLine(string.Format("Second watch: Method '{0}' on object '{1}' was invoked and caught in order {2}.", input.MethodBase.Name, input.Target.GetType(),Order));
return getNext()(input, getNext);
}
Can someone explain and \ or post a link explaining what is happening here. I understand Invoke() is being called but why is the name optional in this case?
Upvotes: 1
Views: 85
Reputation: 48230
GetNextHandler appears to be a delegate which returns a delegate.
Thus calling it yields a delegate which is then called with two parameters.
public delegate void FooDelegate( int n );
public delegate FooDelegate GetFooDelegate();
public void Bar( GetFooDelegate getFoo ) {
getFoo()( 5 );
}
Upvotes: 2