Exemple #1
0
        internal void ValidateConsistency()
        {
            IList <TSourceItem> source = _sourceScalar.getValue(_source, new ObservableCollection <TSourceItem>()) as IList <TSourceItem>;

            // ReSharper disable once AssignNullToNotNullAttribute
            if (!this.SequenceEqual(source.Reverse()))
            {
                throw new ObservableComputationsException(this, "Consistency violation: Reversing.1");
            }
        }
        internal new void ValidateInternalConsistency()
        {
            IList source = _sourceScalarOfTypeComputing.getValue(_sourceOfTypeComputing, new ObservableCollection <object>()) as IList;

            // ReSharper disable once AssignNullToNotNullAttribute
            if (!this.SequenceEqual(source.OfType <TResultItem>()))
            {
                throw new ValidateInternalConsistencyException("Consistency violation: OfTypeComputing.1");
            }
        }
Exemple #3
0
        internal void ValidateConsistency()
        {
            IList <TSourceItem> source = _sourceScalar.getValue(_source, new ObservableCollection <TSourceItem>()) as IList <TSourceItem>;

            // ReSharper disable once PossibleNullReferenceException
            if (_sourceCopy.Count != source.Count)
            {
                throw new ObservableComputationsException(this, "Consistency violation: MinimazingOrMaximazing.1");
            }
            TSourceItem defaultValue = _defaultValue;

            for (int i = 0; i < source.Count; i++)
            {
                TSourceItem sourceItem      = source[i];
                TSourceItem savedSourceItem = _sourceCopy[i];
                if (!savedSourceItem.IsSameAs(sourceItem))
                {
                    throw new ObservableComputationsException(this, "Consistency violation: MinimazingOrMaximazing.2");
                }
            }

            if (source.Count > 0)
            {
                TSourceItem result = _mode == MinimazingOrMaximazingMode.Maximazing
                                        ?  source.Max()
                                        : source.Min();

                if (!result.Equals(_value))
                {
                    throw new ObservableComputationsException(this, "Consistency violation: MinimazingOrMaximazing.3");
                }

                if (source.Count(i => i.Equals(result)) != _valueCount)
                {
                    throw new ObservableComputationsException(this, "Consistency violation: MinimazingOrMaximazing.4");
                }

                if (IsDefaulted)
                {
                    throw new ObservableComputationsException(this, "Consistency violation: MinimazingOrMaximazing.4");
                }
            }
            else
            {
                if (!defaultValue.Equals(_value))
                {
                    throw new ObservableComputationsException(this, "Consistency violation: MinimazingOrMaximazing.5");
                }
                if (!IsDefaulted)
                {
                    throw new ObservableComputationsException(this, "Consistency violation: MinimazingOrMaximazing.4");
                }
            }
        }
        public new void ValidateConsistency()
        {
            IList <TSourceItem>             source1          = (IList <TSourceItem>)_source1Scalar.getValue(_source1, new ObservableCollection <TSourceItem>());
            IList <TSourceItem>             source2          = (IList <TSourceItem>)_source2Scalar.getValue(_source2, new ObservableCollection <TSourceItem>());
            IEqualityComparer <TSourceItem> equalityComparer = _equalityComparerScalar.getValue(_equalityComparer);

            if (!this.SequenceEqual(source1.Intersect(source2, equalityComparer)))
            {
                throw new ObservableComputationsException(this, "Consistency violation: Intersecting.1");
            }
        }
Exemple #5
0
        public new void ValidateConsistency()
        {
            IList <TSourceItem>           source    = _sourceScalarSkippingWhile.getValue(_sourceSkippingWhile, new ObservableCollection <TSourceItem>()) as IList <TSourceItem>;
            Func <TSourceItem, int, bool> predicate = _predicateExpression.Compile();

            // ReSharper disable once AssignNullToNotNullAttribute
            if (!this.SequenceEqual(source.SkipWhile(predicate)))
            {
                throw new ObservableComputationsException(this, "Consistency violation: SkippingWhile.1");
            }
        }
Exemple #6
0
        internal void ValidateConsistency()
        {
            IList <TSourceItem> source     = _sourceScalarTakingWhile.getValue(_sourceTakingWhile, new ObservableCollection <TSourceItem>()) as IList <TSourceItem>;
            OcConsumer          ocConsumer = new OcConsumer();

            // ReSharper disable once AssignNullToNotNullAttribute
            if (!this.SequenceEqual(source.TakeWhile((si, i) => new Computing <bool>(_indexedPredicateExpression.ApplyParameters(si, i)).For(ocConsumer).Value)))
            {
                throw new ObservableComputationsException(this, "Consistency violation: TakingWhile.1");
            }
        }
Exemple #7
0
        internal new void ValidateInternalConsistency()
        {
            IList <TSourceItem> source = _sourceScalarSkipping.getValue(_sourceSkipping, new ObservableCollection <TSourceItem>()) as IList <TSourceItem>;
            int count = _skippingCountScalar.getValue(_skippingCount);

            // ReSharper disable once AssignNullToNotNullAttribute
            if (!this.SequenceEqual(source.Skip(count)))
            {
                throw new ValidateInternalConsistencyException("Consistency violation: Skipping.1");
            }
        }
Exemple #8
0
        public new void ValidateConsistency()
        {
            IList <TOuterSourceItem> source1 = (IList <TOuterSourceItem>)_outerSourceScalar.getValue(_outerSource, new ObservableCollection <TOuterSourceItem>());
            IList <TInnerSourceItem> source2 = (IList <TInnerSourceItem>)_innerSourceScalar.getValue(_innerSource, new ObservableCollection <TInnerSourceItem>());
            Func <TOuterSourceItem, TInnerSourceItem, bool> joinPredicate = JoinPredicateExpression.Compile();

            if (!this.SequenceEqual(source1.SelectMany(item1 => source2.Select(item2 => new JoinPair <TOuterSourceItem, TInnerSourceItem>(item1, item2)).Where(jp => joinPredicate(jp.OuterItem, jp.InnerItem)))))
            {
                throw new ObservableComputationsException(this, "Consistency violation: Joining.1");
            }
        }
        internal void ValidateConsistency()
        {
            IList <TSourceItem> source = (IList <TSourceItem>)_sourceScalar.getValue(_source, new ObservableCollection <TSourceItem>());

            Func <TSourceItem, bool> predicate = _predicateExpression.Compile();

            if (_value != source.All(predicate))
            {
                throw new ObservableComputationsException(this, "Consistency violation: AllComputing.1");
            }
        }
        public new void ValidateConsistency()
        {
            IList <TSourceItem>             source           = (IList <TSourceItem>)_sourceScalarContainsComputing.getValue(_sourceContainsComputing, new ObservableCollection <TSourceItem>());
            TSourceItem                     sourceItem       = _itemScalar.getValue(_item);
            IEqualityComparer <TSourceItem> equalityComparer = _equalityComparerScalar.getValue(_equalityComparer);

            if (_value != source.Contains(sourceItem, equalityComparer))
            {
                throw new ObservableComputationsException(this, "Consistency violation: ContainsComputing.1");
            }
        }
Exemple #11
0
        internal void ValidateInternalConsistency()
        {
            IList <TSourceItem> source = _sourceScalar.getValue(_source, new ObservableCollection <TSourceItem>()) as IList <TSourceItem>;

            // ReSharper disable once PossibleNullReferenceException
            // ReSharper disable once AssignNullToNotNullAttribute
            if (!this.SequenceEqual(source))
            {
                throw new ValidateInternalConsistencyException("Consistency violation: Extending.1");
            }
        }
        public new void ValidateConsistency()
        {
            IList <TSourceItem> source = _sourceScalarTaking.getValue(_sourceTaking, new ObservableCollection <TSourceItem>()) as IList <TSourceItem>;
            int startIndex             = _startIndexScalar.getValue(_startIndex);
            int count = _countScalar.getValue(_countTaking);

            // ReSharper disable once AssignNullToNotNullAttribute
            if (!this.SequenceEqual(source.Skip(startIndex).Take(count)))
            {
                throw new ObservableComputationsException(this, "Consistency violation: Taking.1");
            }
        }
Exemple #13
0
        public new void ValidateConsistency()
        {
            IList <TSourceItem> source   = _sourceScalarSkippingWhile.getValue(_sourceSkippingWhile, new ObservableCollection <TSourceItem>()) as IList <TSourceItem>;
            Consumer            consumer = new Consumer();

            // ReSharper disable once AssignNullToNotNullAttribute
            if (!this.SequenceEqual(source.SkipWhile((si, i) => new Computing <bool>(_predicateExpression.ApplyParameters(si, i)).IsNeededFor(consumer).Value)))
            {
                throw new ObservableComputationsException(this, "Consistency violation: SkippingWhile.1");
            }

            consumer.Dispose();
        }
Exemple #14
0
        internal void ValidateConsistency()
        {
            _sourcePositions.ValidateConsistency();
            IList <TSourceItem> source = _sourceScalar.getValue(_source, new ObservableCollection <TSourceItem>()) as IList <TSourceItem>;

            // ReSharper disable once PossibleNullReferenceException
            if (_itemInfos.Count != source.Count)
            {
                throw new ObservableComputationsException(this, "Consistency violation: Selecting.1");
            }
            Func <TSourceItem, TResultItem> selector = _selectorExpressionOriginal.Compile();

            // ReSharper disable once ConditionIsAlwaysTrueOrFalse
            if (source != null)
            {
                if (_itemInfos.Count != source.Count)
                {
                    throw new ObservableComputationsException(this, "Consistency violation: Selecting.6");
                }

                for (int sourceIndex = 0; sourceIndex < source.Count; sourceIndex++)
                {
                    TSourceItem sourceItem = source[sourceIndex];
                    ItemInfo    itemInfo   = _itemInfos[sourceIndex];

                    if (!EqualityComparer <TResultItem> .Default.Equals(this[sourceIndex], selector(sourceItem)))
                    {
                        throw new ObservableComputationsException(this, "Consistency violation: Selecting.2");
                    }

                    if (_itemInfos[sourceIndex].Index != sourceIndex)
                    {
                        throw new ObservableComputationsException(this, "Consistency violation: Selecting.3");
                    }
                    if (itemInfo.ExpressionWatcher._position != _itemInfos[sourceIndex])
                    {
                        throw new ObservableComputationsException(this, "Consistency violation: Selecting.4");
                    }

                    if (!_itemInfos.Contains((ItemInfo)itemInfo.ExpressionWatcher._position))
                    {
                        throw new ObservableComputationsException(this, "Consistency violation: Selecting.5");
                    }

                    if (itemInfo.ExpressionWatcher._position.Index != sourceIndex)
                    {
                        throw new ObservableComputationsException(this, "Consistency violation: Selecting.7");
                    }
                }
            }
        }
        public new void ValidateConsistency()
        {
            IList <TSourceItem> source = _sourceScalar.getValue(_source, new ObservableCollection <TSourceItem>()) as IList <TSourceItem>;
            TSourceItem         item   = _itemScalar.getValue(_item);

            List <TSourceItem> result = new List <TSourceItem>(source);

            result.Insert(0, item);

            if (!this.SequenceEqual(result))
            {
                throw new ObservableComputationsException(this, "Consistency violation: Prepending.1");
            }
        }
		public void ValidateConsistency()
		{
			_sourceRangePositions.ValidateConsistency();
			IList sources = _sourcesScalar.getValue(_sources, new ObservableCollection<ObservableCollection<TSourceItem>>()) as IList;
			// ReSharper disable once PossibleNullReferenceException
			if (_itemInfos.Count != sources.Count) throw new ObservableComputationsException(this, "Consistency violation: Concatenating.1");

			// ReSharper disable once ConditionIsAlwaysTrueOrFalse
			if (sources != null)
			{
				int index = 0;
				int sourcesCount = sources.Count;
				for (int sourceIndex = 0; sourceIndex < sourcesCount; sourceIndex++)
				{
					IList source = sources[sourceIndex] is IReadScalar<object> scalar ? (IList)scalar.Value : (IList)sources[sourceIndex];
					int plainIndex = index;

					int sourceCount = source?.Count ?? 0;
					for (int sourceItemIndex = 0; sourceItemIndex < sourceCount; sourceItemIndex++)
					{
						// ReSharper disable once PossibleNullReferenceException
						TSourceItem sourceItem = (TSourceItem) source[sourceItemIndex];

						if (!EqualityComparer<TSourceItem>.Default.Equals(this[index], sourceItem))
							throw new ObservableComputationsException(this, "Consistency violation: Concatenating.2");

						index++;
					}

					ItemInfo itemInfo = _itemInfos[sourceIndex];

					if (!Equals(itemInfo.Source, source)) throw new ObservableComputationsException(this, "Consistency violation: Concatenating.2");
					if (itemInfo.Index != sourceIndex)  throw new ObservableComputationsException(this, "Consistency violation: Concatenating.3");
					if (itemInfo.Length != sourceCount)  throw new ObservableComputationsException(this, "Consistency violation: Concatenating.4");
					if (itemInfo.PlainIndex != plainIndex)  throw new ObservableComputationsException(this, "Consistency violation: Concatenating.5");					

					if (_sourceRangePositions.List[sourceIndex].Index != sourceIndex) throw new ObservableComputationsException(this, "Consistency violation: Concatenating.6");
				}
			}
			
			for (int i = 0; i < _itemInfos.Count; i++)
			{
				if (!_sourceRangePositions.List.Contains(_itemInfos[i]))
					throw new ObservableComputationsException(this, "Consistency violation: Concatenating.7");
			}

			if (_sourceRangePositions.List.Count != sources.Count)
					throw new ObservableComputationsException(this, "Consistency violation: Concatenating.15");
		}
        public new void ValidateInternalConsistency()
        {
            IList <TSourceItem>             source           = (IList <TSourceItem>)_sourceScalar.getValue(_sourceDistincting, new ObservableCollection <TSourceItem>());
            IEqualityComparer <TSourceItem> equalityComparer = _equalityComparerScalar.getValue(_equalityComparer);

            if (_equalityComparerScalar == null)
            {
                equalityComparer = EqualityComparer <TSourceItem> .Default;
            }

            if (!this.SequenceEqual(source.Distinct(equalityComparer)))
            {
                throw new ValidateInternalConsistencyException("Consistency violation: Distincting.1");
            }
        }
        internal new void ValidateInternalConsistency()
        {
            IList <TSourceItem> source = _sourceScalar.getValue(_source, new ObservableCollection <TSourceItem>()) as IList <TSourceItem>;

            TSourceItem item = _itemScalar.getValue(Item);

            List <TSourceItem> result = new List <TSourceItem>(source)
            {
                item
            };

            if (!this.SequenceEqual(result))
            {
                throw new ValidateInternalConsistencyException("Consistency violation: Appending.1");
            }
        }
Exemple #19
0
        public new void ValidateConsistency()
        {
            IList <TOuterSourceItem> outerSource = (IList <TOuterSourceItem>)_outerSourceScalar.getValue(_outerSource, new ObservableCollection <TOuterSourceItem>());
            IList <TInnerSourceItem> innerSource = (IList <TInnerSourceItem>)_innerSourceScalar.getValue(_innerSource, new ObservableCollection <TInnerSourceItem>());
            Func <TOuterSourceItem, TInnerSourceItem, bool> joinPredicate = _joinPredicateExpression.Compile();

            var result = outerSource.Select(outerItem =>
                                            new
            {
                Key        = outerItem,
                InnerItems = innerSource.Where(innerItem => joinPredicate(outerItem, innerItem)).ToArray()
            }).ToList();

            if (Count != result.Count())
            {
                throw new ObservableComputationsException(this, "Consistency violation: PredicateGroupJoining.1");
            }

            for (int index = 0; index < result.Count; index++)
            {
                var resultItem = result[index];
                PredicateJoinGroup <TOuterSourceItem, TInnerSourceItem> thisItem = this[index];

                int length = resultItem.InnerItems.Length;
                if (length != thisItem.Count)
                {
                    throw new ObservableComputationsException($"Consistency violation: PredicateGroupJoining.3 {length}");
                }

                EqualityComparer <TInnerSourceItem> equalityComparer = EqualityComparer <TInnerSourceItem> .Default;

                IEnumerator enumerator1 = resultItem.InnerItems.GetEnumerator();
                {
                    using (IEnumerator <TInnerSourceItem> enumerator2 = thisItem.GetEnumerator())
                    {
                        while (enumerator1.MoveNext())
                        {
                            enumerator2.MoveNext();
                            if (!equalityComparer.Equals((TInnerSourceItem)enumerator1.Current, enumerator2.Current))
                            {
                                throw new ObservableComputationsException(this, "Consistency violation: PredicateGroupJoining.4");
                            }
                        }
                    }
                }
            }
        }
        internal void ValidateInternalConsistency()
        {
            IList <TSourceItem> source = _sourceScalar.getValue(_source, new ObservableCollection <TSourceItem>()) as IList <TSourceItem>;

            bool conststent = true;

            _destinationOcDispatcher.Invoke(() => {});
            _destinationOcDispatcher.Invoke(() =>
            {
                conststent = this.SequenceEqual(source);
            });

            if (!conststent)
            {
                throw new ValidateInternalConsistencyException("Consistency violation: CollectionDispatching.1");
            }
        }
Exemple #21
0
        internal void ValidateConsistency()
        {
            IList <TSourceItem> source = _sourceScalarSummarizing.getValue(_sourceSummarizing, new ObservableCollection <TSourceItem>()) as IList <TSourceItem>;

            TSourceItem result = default(TSourceItem);
            // ReSharper disable once PossibleNullReferenceException
            int sourceCount = source.Count;

            for (int index = 0; index < sourceCount; index++)
            {
                result = aggregateFunc(result, source[index]);
            }

            if (!Value.Equals(result))
            {
                throw new ObservableComputationsException(this, "Consistency violation: Summarizing.1");
            }
        }
        internal void ValidateInternalConsistency()
        {
            IList <TSourceItem> source = _sourceScalar.getValue(_source, new ObservableCollection <TSourceItem>()) as IList <TSourceItem>;

            // ReSharper disable once PossibleNullReferenceException
            int     sourceCount = source.Count;
            TResult result      = default(TResult);

            for (int i = 0; i < sourceCount; i++)
            {
                result = _aggregateFunc(source[i], result);
            }

            // ReSharper disable once PossibleNullReferenceException
            if (!result.Equals(_value))
            {
                throw new ValidateInternalConsistencyException("Consistency violation: Aggregating.3");
            }
        }
        public new void ValidateConsistency()
        {
            IList <TSourceItem>      source    = _sourceScalar.getValue(_source, new ObservableCollection <TSourceItem>()) as IList <TSourceItem>;
            Func <TSourceItem, bool> predicate = _predicateExpression.Compile();

            List <int> result = new List <int>();

            // ReSharper disable once PossibleNullReferenceException
            for (int i = 0; i < source.Count; i++)
            {
                if (predicate(source[i]))
                {
                    result.Add(i);
                }
            }

            if (!this.SequenceEqual(result))
            {
                throw new ObservableComputationsException(this, "Consistency violation: IndicesComputing.1");
            }
        }
        public void ValidateConsistency()
        {
            IList source = _sourceScalar.getValue(_source, new ObservableCollection <object>()) as IList;

            // ReSharper disable once PossibleNullReferenceException
            if (Count != source.Count)
            {
                throw new ObservableComputationsException(this, "Consistency violation: Casting.1");
            }

            for (int i = 0; i < source.Count; i++)
            {
                object      sourceItem = source[i];
                TResultItem resultItem = this[i];

                if (!resultItem.IsSameAs(sourceItem))
                {
                    throw new ObservableComputationsException(this, "Consistency violation: Casting.2");
                }
            }
        }
        internal void ValidateConsistency()
        {
            IList <TSourceItem> source = _sourceScalar.getValue(_source, new ObservableCollection <TSourceItem>()) as IList <TSourceItem>;
            int         index          = _indexScalar.getValue(_index);
            TSourceItem defaultValue   = _defaultValue;

            // ReSharper disable once PossibleNullReferenceException
            if (source.Count > index)
            {
                if (!source[index].IsSameAs(_value))
                {
                    throw new ObservableComputationsException(this, "Consistency violation: ItemComputing.1");
                }
            }
            else
            {
                if (!defaultValue.IsSameAs(_value))
                {
                    throw new ObservableComputationsException(this, "Consistency violation: ItemComputing.2");
                }
            }
        }
        internal void ValidateConsistency()
        {
            IList sources = (IList)_sourceScalar.getValue(_source, new ObservableCollection <ObservableCollection <TSourceItem> >());

            IEnumerable <TSourceItem> result = new List <TSourceItem>();

            int sourcesCount = sources.Count;

            for (int index = 0; index < sourcesCount; index++)
            {
                IEnumerable <TSourceItem> source = (IEnumerable <TSourceItem>)sources[index];
                if (source != null)
                {
                    result = result.Union(source);
                }
            }

            if (!this.SequenceEqual(result))
            {
                throw new ObservableComputationsException(this, "Consistency violation: Uniting.1");
            }
        }
Exemple #27
0
        public void ValidateConsistency()
        {
            IList <TOuterSourceItem> outerSource = _outerSourceScalar.getValue(_outerSource, new ObservableCollection <TOuterSourceItem>()) as IList <TOuterSourceItem>;
            IList <TInnerSourceItem> innerSource = _innerSourceScalar.getValue(_innerSource, new ObservableCollection <TInnerSourceItem>()) as IList <TInnerSourceItem>;

            int index = 0;

            // ReSharper disable once PossibleNullReferenceException
            for (int index1 = 0; index1 < outerSource.Count; index1++)
            {
                TOuterSourceItem sourceOuterItem = outerSource[index1];

                // ReSharper disable once PossibleNullReferenceException
                for (int index2 = 0; index2 < innerSource.Count; index2++)
                {
                    TInnerSourceItem sourceInnerItem = innerSource[index2];

                    JoinPair <TOuterSourceItem, TInnerSourceItem> joinPair = this[index];

                    if (!EqualityComparer <TOuterSourceItem> .Default.Equals(joinPair.OuterItem, sourceOuterItem))
                    {
                        throw new ObservableComputationsException(this, "Consistency violation: Crossing.1");
                    }

                    if (!EqualityComparer <TInnerSourceItem> .Default.Equals(joinPair.InnerItem, sourceInnerItem))
                    {
                        throw new ObservableComputationsException(this, "Consistency violation: Crossing.2");
                    }

                    index++;
                }
            }

            // ReSharper disable once PossibleNullReferenceException
            if (Count != outerSource.Count * innerSource.Count)
            {
                throw new ObservableComputationsException(this, "Consistency violation: Crossing.3");
            }
        }
        public new void ValidateConsistency()
        {
            IList <TSourceItem> source = _sourceScalar.getValue(_source, new ObservableCollection <TSourceItem>()) as IList <TSourceItem>;
            Func <TSourceItem, INotifyCollectionChanged>      selector          = _selectorExpression?.Compile();
            Func <TSourceItem, int, INotifyCollectionChanged> selectorWithIndex = _selectorWithIndexExpression?.Compile();

            List <TResultItem> result = new List <TResultItem>();

            // ReSharper disable once PossibleNullReferenceException
            for (var index = 0; index < source.Count; index++)
            {
                TSourceItem sourceItem = source[index];
                // ReSharper disable once PossibleNullReferenceException
                result.AddRange(selector != null ? (IEnumerable <TResultItem>)selector(sourceItem) : (IEnumerable <TResultItem>)selectorWithIndex(sourceItem, index));
            }

            // ReSharper disable once AssignNullToNotNullAttribute
            if (!this.SequenceEqual(result))
            {
                throw new ObservableComputationsException(this, "Consistency violation: SelectingMany.1");
            }
        }
        internal void ValidateConsistency()
        {
            IList <int>             source = _sourceScalar.getValue(_source, new ObservableCollection <int>()) as IList <int>;
            Averaging <int, double> @this  = this as Averaging <int, double>;

            // ReSharper disable once PossibleNullReferenceException
            if (source.Count > 0)
            {
                // ReSharper disable once PossibleNullReferenceException
                // ReSharper disable once CompareOfFloatsByEqualityOperator
                if (source.Average() != @this.Value)
                {
                    throw new ObservableComputationsException(this, "Consistency violation: Averaging.1");
                }
            }
            else
            {
                // ReSharper disable once PossibleNullReferenceException
                if (!double.IsNaN(@this.Value))
                {
                    throw new ObservableComputationsException(this, "Consistency violation: Averaging.2");
                }
            }
        }
Exemple #30
0
        internal void ValidateConsistency()
        {
            _filteredPositions.ValidateConsistency();
            _sourcePositions.ValidateConsistency();

            IList <TSourceItem> source = _sourceScalar.getValue(_source, new ObservableCollection <TSourceItem>()) as IList <TSourceItem>;

            // ReSharper disable once PossibleNullReferenceException
            if (_itemInfos.Count != source.Count)
            {
                throw new ObservableComputationsException(this, "Consistency violation: Filtering.9");
            }
            Func <TSourceItem, bool> predicate1 = _predicateExpression.Compile();
            Func <TSourceItem, FilteringItemInfo, bool> predicate = (si, fii) => fii.PredicateFunc != null?fii.PredicateFunc() : predicate1(si);

            // ReSharper disable once ConditionIsAlwaysTrueOrFalse
            if (source != null)
            {
                if (_itemInfos.Count != source.Count)
                {
                    throw new ObservableComputationsException(this, "Consistency violation: Filtering.14");
                }

                if (_source != null && _filteredPositions.List.Count - 1 != Count)
                {
                    throw new ObservableComputationsException(this, "Consistency violation: Filtering.15");
                }

                if (_source == null && _filteredPositions.List.Count != 0)
                {
                    throw new ObservableComputationsException(this, "Consistency violation: Filtering.16");
                }

                int count = 0;
                int index = 0;
                for (int sourceIndex = 0; sourceIndex < source.Count; sourceIndex++)
                {
                    TSourceItem       sourceItem = source[sourceIndex];
                    FilteringItemInfo itemInfo   = _itemInfos[sourceIndex];
                    if (predicate(sourceItem, itemInfo))
                    {
                        if (itemInfo.FilteredPosition == null)
                        {
                            throw new ObservableComputationsException(this, "Consistency violation: Filtering.2");
                        }

                        if (!EqualityComparer <TSourceItem> .Default.Equals(this[index], sourceItem))
                        {
                            throw new ObservableComputationsException(this, "Consistency violation: Filtering.1");
                        }

                        if (itemInfo.FilteredPosition.Index != index)
                        {
                            throw new ObservableComputationsException(this, "Consistency violation: Filtering.5");
                        }

                        count++;
                        index++;
                    }
                    else
                    {
                        if (itemInfo.FilteredPosition != null)
                        {
                            throw new ObservableComputationsException(this, "Consistency violation: Filtering.3");
                        }
                    }

                    if (_itemInfos[sourceIndex].Index != sourceIndex)
                    {
                        throw new ObservableComputationsException(this, "Consistency violation: Filtering.7");
                    }
                    if (itemInfo.ExpressionWatcher._position != _itemInfos[sourceIndex])
                    {
                        throw new ObservableComputationsException(this, "Consistency violation: Filtering.8");
                    }

                    if (itemInfo.FilteredPosition != null && !_filteredPositions.List.Contains(itemInfo.FilteredPosition))
                    {
                        throw new ObservableComputationsException(this, "Consistency violation: Filtering.10");
                    }

                    if (!_filteredPositions.List.Contains(itemInfo.NextFilteredItemPosition))
                    {
                        throw new ObservableComputationsException(this, "Consistency violation: Filtering.11");
                    }

                    if (!_itemInfos.Contains(itemInfo.ExpressionWatcher._position))
                    {
                        throw new ObservableComputationsException(this, "Consistency violation: Filtering.12");
                    }
                }

                if (_source != null)
                {
                    Position nextFilteredItemPosition = _filteredPositions.List[count];
                    for (int sourceIndex = source.Count - 1; sourceIndex >= 0; sourceIndex--)
                    {
                        TSourceItem       sourceItem = source[sourceIndex];
                        FilteringItemInfo itemInfo   = _itemInfos[sourceIndex];

                        if (itemInfo.NextFilteredItemPosition != nextFilteredItemPosition)
                        {
                            throw new ObservableComputationsException(this, "Consistency violation: Filtering.4");
                        }

                        if (predicate(sourceItem, itemInfo))
                        {
                            nextFilteredItemPosition = itemInfo.FilteredPosition;
                        }
                    }

                    if (_filteredPositions.List.Count != count + 1)
                    {
                        throw new ObservableComputationsException(this, "Consistency violation: Filtering.6");
                    }
                }
            }
        }