Ejemplo n.º 1
0
        private static IList ToList(IDictionary dictionary)
        {
            Type[] typeArguments = TypeInterrogator.GetItemTypes(dictionary.GetType());
            Type   lstkvType     = GenBuilder.BuildType(typeof(KVPair <,>), typeArguments);
            IList  target        = (IList)GenBuilder.BuildInstance(typeof(List <>), new Type[] { lstkvType });

            foreach (DictionaryEntry it in dictionary)
            {
                target.Add(GenBuilder.BuildInstance(lstkvType, new object[] { it.Key, it.Value }));
            }

            return(target);
        }
Ejemplo n.º 2
0
        private static IDictionary LoadDictionary(string fileName, Type dictionaryT)
        {
            Type[] typeArguments   = TypeInterrogator.GetItemTypes(dictionaryT);
            Type   lstKeyValueType = GenBuilder.BuildType(typeof(KVPair <,>), typeArguments);
            Type   lstType         = GenBuilder.BuildType(typeof(List <>), new Type[] { lstKeyValueType });
            IList  list            = (IList)DoLoad(fileName, lstType);

            PropertyInfo keyProperty   = lstKeyValueType.GetProperty("Key");
            PropertyInfo valueProperty = lstKeyValueType.GetProperty("Value");
            IDictionary  target        = (IDictionary)GenBuilder.BuildInstance(typeof(Dictionary <,>), typeArguments);

            foreach (object it in list)
            {
                object key = keyProperty.GetValue(it, null);
                if (key != null)
                {
                    target.Add(key, valueProperty.GetValue(it, null));
                }
            }

            return(target);
        }