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.

image

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# 4.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.