How can I convert an ExpandoObject to Dictionary in C#?

Chris Williams picture Chris Williams · Sep 16, 2015 · Viewed 15.5k times · Source

I'm using Jint to execute JavaScript in a Xamarin app. Jint is converting an associative array into an ExpandoObject. How do I use this object? Ideally, I'd like to get a dictionary of the data out of it.

JavaScript returns:

return {blah:abc, bleh:xyz};

Debugger of Object that Jint returns looks like:

enter image description here

Answer

Zotta picture Zotta · Sep 16, 2015

It already IS a dictionary. Just implicitly cast it:

IDictionary<string, object> dictionary_object = expando_object;

And then use it like one. BTW: this is also the reason why recursive's solution works.