Dynamic Dispatch

After the compiler has done its duty of generating code that will construct call site objects at runtime, all remaining work is left to the runtime. We already discussed in detail how call sites are built, but we haven’t yet discussed how the invocation of the dynamic operation is initiated. In the code that was generated for our running example, you can find the dispatch at the end:

private static void Add([Dynamic] object a, [Dynamic] object b){    // Code to ensure the call site objects are instantiated.    <Add>o__SiteContainer0.<>p__Site1.Target(        <Add>o__SiteContainer0.<>p__Site1, typeof(Console),        <Add>o__SiteContainer0.<>p__Site2.Target(            <Add>o__SiteContainer0.<>p__Site2, ...

Get C# 5.0 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.