Search code examples
javascriptc#dictionaryexpandoobject

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


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


Solution

  • 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.