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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.