private static Variant FindIndex(ProxyArray array, int index) { for (int i = 0; i < array.Count; i++) { if (array[i] is ProxyObject) { ProxyObject proxy = array[i] as ProxyObject; if (proxy.ContainsKey(ProxyArray.CombineHintName)) { int @Index = proxy[ProxyArray.CombineHintName]; if (@Index == index) { return(proxy); } } } } return(null); }
protected static Variant CombineVariant(Variant startingVariant, Variant combineWith) { Type type = null; if (startingVariant != null) { type = startingVariant.GetType(); } else if (combineWith != null) { type = combineWith.GetType(); } else { throw new ArgumentException("Both values are null for combine"); } if (type == typeof(ProxyObject)) { ProxyObject combineObject = combineWith as ProxyObject; ProxyObject startingObject = startingVariant as ProxyObject; foreach (var item in combineObject) { if (startingObject.ContainsKey(item.Key)) { //It had the value so we have to loop over it. startingObject[item.Key] = CombineVariant(startingObject[item.Key], item.Value); } else { //It did not have a value so we can just copy the whole tree startingObject[item.Key] = item.Value; } } } else if (type == typeof(ProxyArray)) { ProxyArray combineArray = combineWith as ProxyArray; ProxyArray startingArray = startingVariant as ProxyArray; for (int i = 0; i < combineArray.Count; i++) { if (combineArray[i] is ProxyObject) { ProxyObject arrayObject = combineArray[i] as ProxyObject; if (arrayObject != null) { if (arrayObject.ContainsKey(ProxyArray.CombineHintName)) { int @Index = arrayObject[ProxyArray.CombineHintName]; Variant indexVariant = FindIndex(startingArray, @Index); if (indexVariant == null) { startingArray.Add(arrayObject); } else { indexVariant = CombineVariant(indexVariant, arrayObject); } } } } } } else if (type == typeof(ProxyNumber)) { startingVariant = combineWith; } else if (type == typeof(ProxyString)) { startingVariant = combineWith; } return(startingVariant); }