List <> of dictionaries <> with unknown type

I am writing a recursive discovery method that 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 somehow declare the list at the beginning. List<Dictionary<string,???>>

I'm currently pickle, does anyone know a solution?

+7
source share
2 answers

Basically, the closest you can find is List<IDictionary> (not a generic IDictionary ).

Given that dictionaries can have different types of keys and values, you still cannot use them in a safe way at compile time.

+11
source

You can wrap the dictionary <> in the class so that it becomes a List <DictionaryWrapper>.

0
source

All Articles