Custom Dynamic Objects with DynamicObject

So far, we haven’t had a chance to control any of the binding logic that happens at runtime when invoking dynamic operations on an object. The flexible infrastructure of the DLR provides a way to create objects that participate in those operations. To achieve this, the simplest route is the use of System.Dynamic.DynamicObject, which is defined as shown in Figure 22.17.


FIGURE 22.17 A look at DynamicObject and IDynamicMetaObjectProvider.

As you can see, this base class contains Try methods for every dynamic operation that’s supported by the DLR. The Binder objects passed as the first argument correspond ...

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.