Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List<> of Dictionaries<> with unknown type

Tags:

c#

generics

I am writing a recursive discovery method, which will basically deserialize an object. This object is always a List of Dictionaries, but sometimes the dictionary will have other Dictionaries as values and sometimes the dictionary will have strings as values.

I need to declare the List at the beginning somehow. List<Dictionary<string,???>>

I am in a pickle at the moment, anybody know a solution?

like image 675
RealityDysfunction Avatar asked Aug 16 '13 18:08

RealityDysfunction


1 Answers

Basically the closest you can come is probably List<IDictionary> (the non-generic IDictionary interface).

Given that the dictionaries can have different key and value types, you wouldn't be able to use them in a type-safe way at compile-time anyway.

like image 80
Jon Skeet Avatar answered Sep 19 '22 11:09

Jon Skeet