Click here to Skip to main content
15,904,416 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I went to interview ,There they ask me that he wanted to order the delegate functions calling in multicast delegate
Posted
Comments
PIEBALDconsult 17-Jul-15 0:47am    
Sure you can. But why? In what order?
Sergey Alexandrovich Kryukov 17-Jul-15 1:20am    
There are such use cases, but in this case, this is just the check of the depth of understanding of delegates. Of course, this is not a mainstream design feature of multicast delegates, but I find it important that the access to individual delegate members of the invocation list of a delegate instance is provided. If you read my Solution 1 and look at the referenced sections of my article, you may find it interesting enough.
—SA
PIEBALDconsult 17-Jul-15 1:23am    
I recall that either OG or JSOP posted something on it some time ago, and I've used it for other purposes. But sorting them is probably not a real-world requirement.
Sergey Alexandrovich Kryukov 17-Jul-15 1:44am    
Oh, it seems to be totally impractical, and bad design practice, quite bad (I mean reordering; just the opposite, the handling should not introduce any dependency on the order, never), but the question is not about anything practical. This is an interesting question which can help to reveal in-depth knowledge of how things work. Isn't it valuable?

I only would be against asking such question at the interview by different reason. The knowledge of this delicate API detail itself should not be taken too seriously. It is not so important if a person faced with the need for such a deep detail or not. The only important thing is the ability of the person to get into such detail and, reasonably quickly, make them work. But this is much harder to evaluate.

Anyway, all that does not make this question less interesting. At least it demonstrate that interviewer has pretty deep understanding of the subject, which I observe quite rarely.

—SA

1 solution

Yes, of course. This is explained in my article Dynamic Method Dispatcher.

In the referenced chapter "4.2. Return Values" I demonstrate one of the use cases of my MuticastDynamicMethodDispatcher generic class when I have to call each element delegate instance of the multicast delegate instance one by one. In my code, I do this for the purpose of giving the user the possibility to declare a custom rule for accumulating of the return values (see third paragraph, "The most sophisticated method of returning…"), but you can use this technique for anything else, for example, for reordering the calls.

If you execute the use-case code sample with my library under the debugger, you will see that implementation accesses the invocation list of the multicast delegate instance and traverse it to make individual invocation for each element, separately.

For understanding the background of some important delicate aspects of the internal structure of the delegate instances, you should better read the previous section, Dynamic Method Dispatcher; 4.1. On the Nature of Delegate Instance.

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900