0

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.

Eldar
  • 9,781
  • 2
  • 10
  • 35
decentish
  • 3
  • 1

1 Answers1

0

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();
Eldar
  • 9,781
  • 2
  • 10
  • 35
  • I completely forgot that it returned a list when I switched to the method of converting it to a dictionary, thanks for the help. – decentish Oct 22 '22 at 16:38