示例#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);
        }
示例#2
0
        public object ToPropertyValue(object cv)
        {
            Dictionary <string, string> converted = (Dictionary <string, string>)cv;

            if (_keyType == typeof(string) && _valueType == typeof(string))
            {
                return(converted);
            }

            IDictionary dictionary = (IDictionary)GenBuilder.BuildInstance(typeof(Dictionary <,>), new Type[] { _keyType, _valueType });

            foreach (KeyValuePair <string, string> kv in converted)
            {
                dictionary.Add((new StrAdapter(kv.Key)), (new StrAdapter(kv.Value)));
            }

            return(dictionary);
        }
示例#3
0
        public int SetObject(IEnumerable objCollection, CellBorderStyle borderStyle)
        {
            _borderStyle = borderStyle;

            Type objType = objCollection.GetType();

            if (TypeInterrogator.IsDictionaryType(objType))
            {
                _iter = new Traverser(CollConverter.ToList(objCollection, GenBuilder.BuildKeyValueType(objType)));
            }
            else
            {
                _iter = new Traverser(CollConverter.ToList(objCollection));
            }

            _objControl.SetObject(_iter.First, null, _borderStyle);

            return(0);
        }
示例#4
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);
        }