public ArrayWrapper(object collection, int index, CollectionChangedDelegate onCollectionChanged) : base(index) { Check.IsNotNull("collection", collection); _UnTypedcollection = collection as IList; _TypedList = collection as IList <T>; if (_UnTypedcollection == null && _TypedList == null) { throw new Exception("unknown collection : " + collection.GetType().ToString()); } _onCollectionChanged = onCollectionChanged; if (collection is ICollectionChanged) { ((ICollectionChanged)collection).CollectionChanged += new EventHandler <CollectionChangedEventArgs>(ArrayWrapper_CollectionChanged); } #if !SILVERLIGHT else if (collection is IBindingList) { ((IBindingList)collection).ListChanged += new ListChangedEventHandler(ArrayWrapper_ListChanged); } #endif //TODO: INotifyCollectionChanged _originalCollection = new WeakReference(collection); //_originalCollection = collection; }
void castCollection_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { CollectionChangedDelegate changeHandler = OnCollectionChanged; m_dispatcher.EnsureThread(changeHandler, sender, e); }
private object CreateArrayWrapper(PathItem srcPathItem, PathItem destPathItem, out bool isValid, CollectionChangedDelegate onCollectionChanged) { isValid = true; PropertyInfo pi = destPathItem.Source.Target.GetType().GetProperty(destPathItem.PropertyName); object collection = pi.GetValue(destPathItem.Source.Target, null); Type srcType; if (srcPathItem.IsArray) { srcType = GetArrayItemPropertyType(srcPathItem); } else { srcType = srcPathItem.Source.Target.GetType().GetProperty(srcPathItem.PropertyName).PropertyType; } if (srcType == null) { srcType = typeof(object); isValid = false; } Type tArrayWrapper = typeof(ArrayWrapper <>).MakeGenericType(srcType); object aw = Activator.CreateInstance(tArrayWrapper, collection, destPathItem.ArrayIndex, onCollectionChanged); return(aw); }