Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 480
Chris Williams Avatar asked Sep 16 '15 20:09

Chris Williams


2 Answers

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.

like image 97
Zotta Avatar answered Sep 18 '22 20:09

Zotta


Just pass it to the constructor.

var dictionary = new Dictionary<string, object>(result);
like image 25
recursive Avatar answered Sep 17 '22 20:09

recursive