Home > Blockchain >  Cannot implicitly convert ExpandoObject to IDictionary in c#
Cannot implicitly convert ExpandoObject to IDictionary in c#

Time:10-23

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:

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.

CodePudding user response:

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();
  • Related