private object GenerateEditableKeyValuePair(object source) { var sourceType = source.GetType(); if ((sourceType.GetGenericArguments() == null) || (sourceType.GetGenericArguments().GetLength(0) != 2)) { return(null); } var propInfoKey = sourceType.GetProperty("Key"); var propInfoValue = sourceType.GetProperty("Value"); if ((propInfoKey != null) && (propInfoValue != null)) { return(ListUtilities.CreateEditableKeyValuePair(propInfoKey.GetValue(source, null) , sourceType.GetGenericArguments()[0] , propInfoValue.GetValue(source, null) , sourceType.GetGenericArguments()[1])); } return(null); }
public void OnItemSourceChanged(IEnumerable oldValue, IEnumerable newValue) { if (newValue != null) { var dict = newValue as IDictionary; if (dict != null) { // A Dictionary contains KeyValuePair that can't be edited. // We need to Add EditableKeyValuePairs from DictionaryEntries. foreach (DictionaryEntry item in dict) { var keyType = (item.Key != null) ? item.Key.GetType() : (dict.GetType().GetGenericArguments().Count() > 0) ? dict.GetType().GetGenericArguments()[0] : typeof(object); var valueType = (item.Value != null) ? item.Value.GetType() : (dict.GetType().GetGenericArguments().Count() > 1) ? dict.GetType().GetGenericArguments()[1] : typeof(object); var editableKeyValuePair = ListUtilities.CreateEditableKeyValuePair(item.Key , keyType , item.Value , valueType); this.Items.Add(editableKeyValuePair); } } else { foreach (var item in newValue) { if (item != null) { Items.Add(item); } } } } }