コード例 #1
0
ファイル: Core.cs プロジェクト: xtds/ChangeTracking
        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 NotifyPropertyChangedInterceptor(ChangeTrackingInterceptor <T> changeTrackingInterceptor)
 {
     _PropertyChangedEventHandlers             = new Dictionary <string, PropertyChangedEventHandler>();
     _ListChangedEventHandlers                 = new Dictionary <string, ListChangedEventHandler>();
     changeTrackingInterceptor._StatusChanged += (o, e) => RaisePropertyChanged(o, nameof(IChangeTrackable.ChangeTrackingStatus));
     PropertyChanged += delegate { };
 }
コード例 #3
0
 internal NotifyPropertyChangedInterceptor(ChangeTrackingInterceptor <T> changeTrackingInterceptor)
 {
     _PropertyChangedEventHandlers                        = new Dictionary <string, PropertyChangedEventHandler>();
     _PropertyChangedEventHandlersLock                    = new object();
     _ListChangedEventHandlers                            = new Dictionary <string, ListChangedEventHandler>();
     _ListChangedEventHandlersLock                        = new object();
     _CurrentlyExecutingPropertyChangedEvents             = new HashSet <string>();
     _CurrentlyExecutingPropertyChangedEventsLock         = new object();
     changeTrackingInterceptor._StatusChanged            += (o, e) => RaisePropertyChanged(o, nameof(IChangeTrackable.ChangeTrackingStatus));
     changeTrackingInterceptor._ChangedPropertiesChanged += (o, e) => RaisePropertyChanged(o, nameof(IChangeTrackable.ChangedProperties));
     PropertyChanged += delegate { };
 }
コード例 #4
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);
        }