示例#1
0
        internal static T AsTrackable <T>(this T target, ChangeStatus status, Action <T> notifyParentListItemCanceled, bool makeComplexPropertiesTrackable, bool makeCollectionPropertiesTrackable) where T : class
        {
            //if T was ICollection<T> it would of gone to one of the other overloads
            if (target as ICollection != null)
            {
                throw new InvalidOperationException("Only IList<T>, List<T> and ICollection<T> are supported");
            }

            var    changeTrackingInterceptor        = new ChangeTrackingInterceptor <T>(status);
            var    notifyPropertyChangedInterceptor = new NotifyPropertyChangedInterceptor <T>(changeTrackingInterceptor);
            var    editableObjectInterceptor        = new EditableObjectInterceptor <T>(notifyParentListItemCanceled);
            var    complexPropertyInterceptor       = new ComplexPropertyInterceptor <T>(makeComplexPropertiesTrackable, makeCollectionPropertiesTrackable);
            var    collectionPropertyInterceptor    = new CollectionPropertyInterceptor <T>(makeComplexPropertiesTrackable, makeCollectionPropertiesTrackable);
            object proxy = _ProxyGenerator.CreateClassProxyWithTarget(typeof(T),
                                                                      new[] { typeof(IChangeTrackableInternal), typeof(IChangeTrackable <T>), typeof(IChangeTrackingManager), typeof(IComplexPropertyTrackable), typeof(ICollectionPropertyTrackable), typeof(IEditableObject), typeof(System.ComponentModel.INotifyPropertyChanged) },
                                                                      target,
                                                                      GetOptions(typeof(T)),
                                                                      notifyPropertyChangedInterceptor,
                                                                      changeTrackingInterceptor,
                                                                      editableObjectInterceptor,
                                                                      complexPropertyInterceptor,
                                                                      collectionPropertyInterceptor);

            CopyFields(source: target, target: proxy);
            notifyPropertyChangedInterceptor.IsInitialized = true;
            changeTrackingInterceptor.IsInitialized        = true;
            editableObjectInterceptor.IsInitialized        = true;
            complexPropertyInterceptor.IsInitialized       = true;
            collectionPropertyInterceptor.IsInitialized    = true;
            return((T)proxy);
        }
示例#2
0
        internal static T AsTrackable <T>(this T target, ChangeStatus status, Action <T> notifyParentListItemCanceled, bool makeComplexPropertiesTrackable, bool makeCollectionPropertiesTrackable, Graph graph) where T : class
        {
            ThrowIfTargetIsProxy(target);
            ProxyWeakTargetMap existing = graph.GetExistingProxyForTarget(target);

            if (existing != null)
            {
                return((T)existing.Proxy);
            }

            //if T was ICollection<T> it would of gone to one of the other overloads
            if (target as ICollection != null)
            {
                throw new InvalidOperationException("Only IList<T>, List<T> and ICollection<T> are supported");
            }

            var    changeTrackingInterceptor        = new ChangeTrackingInterceptor <T>(status);
            var    notifyPropertyChangedInterceptor = new NotifyPropertyChangedInterceptor <T>(changeTrackingInterceptor);
            var    editableObjectInterceptor        = new EditableObjectInterceptor <T>(notifyParentListItemCanceled);
            var    complexPropertyInterceptor       = new ComplexPropertyInterceptor <T>(makeComplexPropertiesTrackable, makeCollectionPropertiesTrackable, graph);
            var    collectionPropertyInterceptor    = new CollectionPropertyInterceptor <T>(makeComplexPropertiesTrackable, makeCollectionPropertiesTrackable, graph);
            object proxy = _ProxyGenerator.CreateClassProxyWithTarget(typeof(T),
                                                                      new[] { typeof(IChangeTrackableInternal), typeof(IRevertibleChangeTrackingInternal), typeof(IChangeTrackable <T>), typeof(IChangeTrackingManager), typeof(IComplexPropertyTrackable), typeof(ICollectionPropertyTrackable), typeof(IEditableObjectInternal), typeof(INotifyPropertyChanged) },
                                                                      target,
                                                                      GetOptions(typeof(T)),
                                                                      notifyPropertyChangedInterceptor,
                                                                      changeTrackingInterceptor,
                                                                      editableObjectInterceptor,
                                                                      complexPropertyInterceptor,
                                                                      collectionPropertyInterceptor);

            CopyFields(source: target, target: proxy);
            notifyPropertyChangedInterceptor.IsInitialized = true;
            changeTrackingInterceptor.IsInitialized        = true;
            editableObjectInterceptor.IsInitialized        = true;
            complexPropertyInterceptor.IsInitialized       = true;
            collectionPropertyInterceptor.IsInitialized    = true;
            graph.Add(new ProxyWeakTargetMap(target, proxy));
            return((T)proxy);
        }