IDynamicObject
, the glue behind dynamic
, allows interpretation of a call at runtime.
This is interesting for inherently untyped scenarios such as REST, XML, COM, DataSet
, dynamic languages, and many others. It is an implementation of dynamic dispatch built on top of the Dynamic Language Runtime (DLR).
Instead of cumbersome reflection semantics, you dot into variables declared as dynamic
. Imagine working with Javascript objects from Silverlight:
dynamic obj = GetScriptObject();
HtmlPage.Window.Alert(obj.someProperty);
All C# syntax is supported (I believe):
HtmlPage.Window.Alert(obj.someMethod() + obj.items[0]);
Reflection itself looks a lot cleaner:
public void WriteSomePropertyValue(object target)
{
Console.WriteLine((target as dynamic).SomeProperty);
}
public void WriteSomeMethodValue(object target, int arg1, string arg2)
{
Console.WriteLine((target as dynamic).SomeMethod(arg1, arg2));
}
dynamic
is another tool in the toolkit. It does not change the static vs. dynamic debate, it simply eases the friction.