Hemme's Blog

Stories from behind the keyboard

  • RSS
  • Twitter
  • Linkedin

LINQPad 4 doesn’t seem to let you Dump() an ExpandoObject. For instance, the following code doesn’t compile:

dynamic x = new ExpandoObject();
x.Name = "Mario";
x.Age = 23;
x.Dump();

A simple solution is to cast the object to an IDictionary<string,object>:

dynamic x = new ExpandoObject();
x.Name = "Mario";
x.Age = 23;
((IDictionary<string,object>)x).Dump();

The Dump().

By the way, casting to IDictionary<string,object> is the way you can control the dynamic properties of an ExpandoObject, as described in MSDN website.

Edit: Joe Albahari pointed out that you can simply cast an ExpandoObject to (object). For instance:

//...
((object)x).Dump();

Happy programming!

No comments: