コード例 #1
0
        public ObservableCollectionSnapshot(DirtyModelDetector modelDetector,
                                            INotifyCollectionChanged iCollectionAsINotifyCollectionChanged, IEnumerable listenedCollectionAsIEnumerable)
            : base(modelDetector, iCollectionAsINotifyCollectionChanged)
        {
            if (iCollectionAsINotifyCollectionChanged == null)
            {
                throw new ArgumentNullException("iCollectionAsINotifyCollectionChanged");
            }
            if (listenedCollectionAsIEnumerable == null)
            {
                throw new ArgumentNullException("listenedCollectionAsIEnumerable");
            }
            if (!ReferenceEquals(iCollectionAsINotifyCollectionChanged, listenedCollectionAsIEnumerable))
            {
                throw new Exception("Same instance expected");
            }

            _listenedCollectionAsINotifyCollectionChanged = iCollectionAsINotifyCollectionChanged;
            _listenedCollectionAsIEnumerable = listenedCollectionAsIEnumerable;

            var itemsSnapshot = new List <SnapshotElement>();

            foreach (var item in _listenedCollectionAsIEnumerable)
            {
                itemsSnapshot.Add(SnaphotFactory.Create(modelDetector, item));
            }
            _itemsSnapshot = new ReadOnlyCollection <SnapshotElement>(itemsSnapshot);
            _listenedCollectionAsINotifyCollectionChanged.CollectionChanged += OnCollectionChanged;
        }
コード例 #2
0
        public NotifyPropertyChangedSnapshot(DirtyModelDetector modelDetector, INotifyPropertyChanged snapshotValue)
            : base(modelDetector, snapshotValue)
        {
            if (snapshotValue == null)
            {
                throw new ArgumentNullException("snapshotValue");
            }

            foreach (var propertyInfo in snapshotValue.GetType().GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public))
            {
                var getMethod = propertyInfo.GetGetMethod();
                if (getMethod != null && getMethod.GetParameters().Any())
                {
                    continue;
                }
                var attributes = propertyInfo.GetCustomAttributes(typeof(IsSerialized), true);
                if (attributes.Length <= 0)
                {
                    continue;
                }

                var snapshot     = SnaphotFactory.Create(modelDetector, propertyInfo.GetValue(snapshotValue, null));
                var keyValuePair = new KeyValuePair <PropertyInfo, SnapshotElement>(propertyInfo, snapshot);
                _propertiesSnapshots.Add(propertyInfo.Name, keyValuePair);
            }

            _listenedNotifyPropertyChanged = snapshotValue;
            _listenedNotifyPropertyChanged.PropertyChanged += OnPropertyChanged;
        }
コード例 #3
0
        public NotifyPropertyChangedSnapshot(DirtyModelDetector modelDetector, INotifyPropertyChanged snapshotValue)
            : base(modelDetector, snapshotValue)
        {
            if (snapshotValue == null)
            {
                throw new ArgumentNullException("snapshotValue");
            }

            foreach (var propertyInfo in snapshotValue.GetType().GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public))
            {
                var getMethod = propertyInfo.GetGetMethod();
                if (getMethod != null && getMethod.GetParameters().Any())
                {
                    continue;
                }
                var attributes = propertyInfo.GetCustomAttributes(typeof(IsSerialized), true);
                if (attributes.Length <= 0)
                {
                    continue;
                }

                var snapshot = SnaphotFactory.Create(modelDetector, propertyInfo.GetValue(snapshotValue, null));
                var keyValuePair = new KeyValuePair<PropertyInfo, SnapshotElement>(propertyInfo, snapshot);
                _propertiesSnapshots.Add(propertyInfo.Name, keyValuePair);

            }

            _listenedNotifyPropertyChanged = snapshotValue;
            _listenedNotifyPropertyChanged.PropertyChanged += OnPropertyChanged;
        }
コード例 #4
0
 internal SnapshotElement(DirtyModelDetector modelDetector, object snapshotValue)
 {
     if (modelDetector == null)
     {
         throw new ArgumentNullException("modelDetector");
     }
     _modelDetector = modelDetector;
     _snapshotValue = snapshotValue;
 }
コード例 #5
0
ファイル: SnapshotElement.cs プロジェクト: ruisebastiao/WPF
 internal SnapshotElement(DirtyModelDetector modelDetector, object snapshotValue)
 {
     if (modelDetector == null)
     {
         throw new ArgumentNullException("modelDetector");
     }
     _modelDetector = modelDetector;
     _snapshotValue = snapshotValue;
 }
コード例 #6
0
ファイル: SnaphotFactory.cs プロジェクト: sk8tz/WPF
        /// <summary>
        /// Create <see cref="SnapshotElement"/> according to given objet type
        /// </summary>
        /// <param name="dirtyModelDetector"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static SnapshotElement Create(DirtyModelDetector dirtyModelDetector, object value)
        {
            var valueAsINotifyCollectionChanged = value as INotifyCollectionChanged;
            var valueAsIEnumerable = value as IEnumerable;

            if (valueAsINotifyCollectionChanged != null && valueAsIEnumerable != null)
            {
                return(new ObservableCollectionSnapshot(dirtyModelDetector, valueAsINotifyCollectionChanged, valueAsIEnumerable));
            }
            else
            {
                var valueAsINotifyPropertyChanged = value as INotifyPropertyChanged;
                if (valueAsINotifyPropertyChanged != null)
                {
                    return(new NotifyPropertyChangedSnapshot(dirtyModelDetector, valueAsINotifyPropertyChanged));
                }
                else
                {
                    return(new EqualsComparatorSnapshot(dirtyModelDetector, value));
                }
            }
        }
コード例 #7
0
        public ObservableCollectionSnapshot(DirtyModelDetector modelDetector,
            INotifyCollectionChanged iCollectionAsINotifyCollectionChanged, IEnumerable listenedCollectionAsIEnumerable)
            : base(modelDetector, iCollectionAsINotifyCollectionChanged)
        {
            if (iCollectionAsINotifyCollectionChanged == null)
                throw new ArgumentNullException("iCollectionAsINotifyCollectionChanged");
            if (listenedCollectionAsIEnumerable == null)
                throw new ArgumentNullException("listenedCollectionAsIEnumerable");
            if (!ReferenceEquals(iCollectionAsINotifyCollectionChanged, listenedCollectionAsIEnumerable))
                throw new Exception("Same instance expected");

            _listenedCollectionAsINotifyCollectionChanged = iCollectionAsINotifyCollectionChanged;
            _listenedCollectionAsIEnumerable = listenedCollectionAsIEnumerable;

            var itemsSnapshot = new List<SnapshotElement>();
            foreach (var item in _listenedCollectionAsIEnumerable)
            {
                itemsSnapshot.Add(SnaphotFactory.Create(modelDetector, item));
            }
            _itemsSnapshot = new ReadOnlyCollection<SnapshotElement>(itemsSnapshot);
            _listenedCollectionAsINotifyCollectionChanged.CollectionChanged += OnCollectionChanged;
        }
コード例 #8
0
ファイル: SnaphotFactory.cs プロジェクト: ruisebastiao/WPF
        /// <summary>
        /// Create <see cref="SnapshotElement"/> according to given objet type
        /// </summary>
        /// <param name="dirtyModelDetector"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static SnapshotElement Create(DirtyModelDetector dirtyModelDetector, object value)
        {
            var valueAsINotifyCollectionChanged = value as INotifyCollectionChanged;
            var valueAsIEnumerable = value as IEnumerable;
            if (valueAsINotifyCollectionChanged != null && valueAsIEnumerable != null)
            {
                return new ObservableCollectionSnapshot(dirtyModelDetector, valueAsINotifyCollectionChanged, valueAsIEnumerable);
            }
            else
            {
                var valueAsINotifyPropertyChanged = value as INotifyPropertyChanged;
                if (valueAsINotifyPropertyChanged != null)
                {
                    return new NotifyPropertyChangedSnapshot(dirtyModelDetector, valueAsINotifyPropertyChanged);

                }
                else
                {
                    return new EqualsComparatorSnapshot(dirtyModelDetector, value);
                }

            }
        }
コード例 #9
0
ファイル: DirtyModelDetector.Test.cs プロジェクト: sk8tz/WPF
 public void SetUp()
 {
     _modelDirtyDetector = new DirtyModelDetector();
     _testingClassA      = CreateNewClassA();
 }
コード例 #10
0
 public EqualsComparatorSnapshot(DirtyModelDetector modelDetector, object snapshotValue)
     : base(modelDetector, snapshotValue)
 {
 }
コード例 #11
0
ファイル: EqualsComparatorSnapshot.cs プロジェクト: sk8tz/WPF
 public EqualsComparatorSnapshot(DirtyModelDetector modelDetector, object snapshotValue)
     : base(modelDetector, snapshotValue)
 {
 }