コード例 #1
0
        internal static object AsTrackableChild(Type type, object target, Action <object> notifyParentItemCanceled, bool makeComplexPropertiesTrackable, bool makeCollectionPropertiesTrackable, Internal.Graph graph)
        {
            ThrowIfTargetIsProxy(target);
            ProxyWeakTargetMap existing = graph.GetExistingProxyForTarget(target);

            if (existing != null)
            {
                return(existing.Proxy);
            }
            var    changeTrackingInterceptor        = CreateInstance(typeof(ChangeTrackingInterceptor <>).MakeGenericType(type), ChangeStatus.Unchanged);
            var    notifyPropertyChangedInterceptor = CreateInstance(typeof(NotifyPropertyChangedInterceptor <>).MakeGenericType(type), changeTrackingInterceptor);
            var    editableObjectInterceptor        = CreateInstance(typeof(EditableObjectInterceptor <>).MakeGenericType(type), notifyParentItemCanceled);
            var    complexPropertyInterceptor       = CreateInstance(typeof(ComplexPropertyInterceptor <>).MakeGenericType(type), makeComplexPropertiesTrackable, makeCollectionPropertiesTrackable, graph);
            var    collectionPropertyInterceptor    = CreateInstance(typeof(CollectionPropertyInterceptor <>).MakeGenericType(type), makeComplexPropertiesTrackable, makeCollectionPropertiesTrackable, graph);
            object proxy = _ProxyGenerator.CreateClassProxyWithTarget(type,
                                                                      new[] { typeof(IChangeTrackableInternal), typeof(IRevertibleChangeTrackingInternal), typeof(IChangeTrackable <>).MakeGenericType(type), typeof(IChangeTrackingManager), typeof(IComplexPropertyTrackable), typeof(ICollectionPropertyTrackable), typeof(IEditableObjectInternal), typeof(INotifyPropertyChanged) },
                                                                      target,
                                                                      GetOptions(type),
                                                                      (IInterceptor)notifyPropertyChangedInterceptor,
                                                                      (IInterceptor)changeTrackingInterceptor,
                                                                      (IInterceptor)editableObjectInterceptor,
                                                                      (IInterceptor)complexPropertyInterceptor,
                                                                      (IInterceptor)collectionPropertyInterceptor);

            CopyFields(type: type, source: target, target: proxy);
            ((IInterceptorSettings)notifyPropertyChangedInterceptor).IsInitialized = true;
            ((IInterceptorSettings)changeTrackingInterceptor).IsInitialized        = true;
            ((IInterceptorSettings)editableObjectInterceptor).IsInitialized        = true;
            ((IInterceptorSettings)complexPropertyInterceptor).IsInitialized       = true;
            ((IInterceptorSettings)collectionPropertyInterceptor).IsInitialized    = true;
            graph.Add(new ProxyWeakTargetMap(target, proxy));
            return(proxy);
        }
コード例 #2
0
        internal static object AsTrackableCollectionChild(Type type, object target, bool makeComplexPropertiesTrackable, bool makeCollectionPropertiesTrackable, Graph graph)
        {
            ThrowIfTargetIsProxy(target);
            ProxyWeakTargetMap existing = graph.GetExistingProxyForTarget(target);

            if (existing != null)
            {
                return(existing.Proxy);
            }
            Type   genericArgument = type.GetGenericArguments().First();
            object proxy           = _ProxyGenerator.CreateInterfaceProxyWithTarget(typeof(IList <>).MakeGenericType(genericArgument),
                                                                                    new[] { typeof(IChangeTrackableCollection <>).MakeGenericType(genericArgument), typeof(IRevertibleChangeTrackingInternal), typeof(IBindingList), typeof(ICancelAddNew), typeof(INotifyCollectionChanged) },
                                                                                    target,
                                                                                    GetOptions(genericArgument),
                                                                                    (IInterceptor)CreateInstance(typeof(ChangeTrackingCollectionInterceptor <>).MakeGenericType(genericArgument), target, makeComplexPropertiesTrackable, makeCollectionPropertiesTrackable, graph));

            graph.Add(new ProxyWeakTargetMap(target, proxy));
            return(proxy);
        }
コード例 #3
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);
        }