Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Cannot implicitly convert ExpandoObject to IDictionary in c#

I’m working on a game in Unity using c#, and I have a class that converts my leaderboard spreadsheet to an ExpandoObject. Unity isn’t allowing me to access its properties of it, so I’m trying to convert it to an IIDictionary, which I know works better. This was my code:

IDictionary<string, object> sheetData = gsh.GetDataFromSheet(gsp);

(GetDataFromSheet returning an ExpandoObject)

Here is the error it is giving me:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Assets\Scripts\LeaderboardSpreadsheet.cs(36,56): error CS0266: Cannot implicitly convert type ‘System.Collections.Generic.List<System.Dynamic.ExpandoObject>’ to ‘System.Collections.Generic.IDictionary<string, object>’. An explicit conversion exists (are you missing a cast?)

How would I do an explicit cast? If there are other types that I could convert the ExpandoObject to, that would be helpful.

>Solution :

GetDataFromSheet method is returning a list of expando objects. The ExpandoObject is already a dictionary so what you can have is a list of dictionaries. And you can do this like below :

var dictionaries = gsh.GetDataFromSheet(gsp).Cast<IDictionary<string,object>>().ToList();
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading