I need to create an IList with the keys and another IList with the values, taken from an IDictionary. How do I do it? I had to avoid generics (List<> and Dictionary<>) because the types inside them are user defined types not known at compile time.
I have a method that processes a DataTable and return a dictionary. The type of the dictionary keys are defined at runtime:
DataTable myDataTable = ....
Type dictionaryKeysType=Type.GetType("myType");
IDictionary myDictionary = ProcessDataTable (myDataTable, dictionaryKeysType);
IList keys= (IList)myDictionary.Keys;
IList values= (IList)myDictionary.Values;
How do I do it? I had to avoid generics (List<> and Dictionary<>) because the types inside them are user defined types not known at compile time. So, althought the method returns a 'Dictionary<>', I cant declare:
Dictionary<dictionaryKeysType, int> myDictionary = ProcessDataTable (myDataTable, dictionaryKeysType)
so I must receive it as a 'IDictionary'. Using 'var' is not a solution, as as the problem would come later when trying to cast it to 'Dictionary'
My code compiles but raises an exception when converting to IList. For example, if "myType" is "uint", I get: (Can't convert an object of type 'KeyCollection[System.UInt32,System.Int32]' to type 'System.Collections.IList').
Please, help :(