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); }
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); }
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); }
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); }