private void processSource(bool replaceSource) { int originalCount = _items.Count; if (_sourceReadAndSubscribed) { int itemInfosCount = _itemInfos.Count; for (int index = 0; index < itemInfosCount; index++) { ItemInfo itemInfo = _itemInfos[index]; if (itemInfo.Source != null) { itemInfo.Source.CollectionChanged -= itemInfo.SourceNotifyCollectionChangedEventHandler; if (itemInfo.SourceAsINotifyPropertyChanged != null) { itemInfo.SourceAsINotifyPropertyChanged.PropertyChanged -= itemInfo.SourcePropertyChangedEventHandler; } } if (itemInfo.SourceScalar != null) { itemInfo.SourceScalar.PropertyChanged -= itemInfo.SourceScalarPropertyChangedEventHandler; } } Utils.initializeItemInfos( Utils.getCapacity(_sourceScalar, _source), out _itemInfos, out _sourceRangePositions); if (replaceSource) { Utils.unsubscribeSource( _source, ref _sourceAsINotifyPropertyChanged, this, handleSourceCollectionChanged); } _sourceReadAndSubscribed = false; } if (replaceSource) { Utils.replaceSource(ref _source, _sourceScalar, _downstreamConsumedComputings, _consumers, this, out _sourcesAsList, true); } if (_source != null && _isActive) { if (replaceSource) { Utils.subscribeSource( out _sourceAsIHasTickTackVersion, _sourcesAsList, ref _lastProcessedSourcesTickTackVersion, ref _sourceAsINotifyPropertyChanged, (ISourceIndexerPropertyTracker)this, _source, handleSourceCollectionChanged); } int plainIndex = 0; int count = _sourcesAsList.Count; object[] sourcesCopy = new object[count]; _sourcesAsList.CopyTo(sourcesCopy, 0); for (int index = 0; index < count; index++) { object sourceItemObject = sourcesCopy[index]; IList sourceItem = sourceItemObject is IReadScalar <object> sourceItemScalar ? (IList)sourceItemScalar.Value : (IList)sourceItemObject; int sourceItemCount = sourceItem?.Count ?? 0; ItemInfo itemInfo = _sourceRangePositions.Add(sourceItemCount); registerSourceItem(sourceItemObject, itemInfo); IList <TSourceItem> sourceCopy = itemInfo.SourceCopy; for (int sourceSourceIndex = 0; sourceSourceIndex < sourceItemCount; sourceSourceIndex++) { if (originalCount > plainIndex) { // ReSharper disable once PossibleNullReferenceException _items[plainIndex++] = sourceCopy[sourceSourceIndex]; } else { // ReSharper disable once PossibleNullReferenceException _items.Insert(plainIndex++, sourceCopy[sourceSourceIndex]); } } } for (int index = originalCount - 1; index >= plainIndex; index--) { _items.RemoveAt(index); } _sourceReadAndSubscribed = true; } else { _items.Clear(); } reset(); }
private Concatenating(int initialCapacity) : base(initialCapacity) { Utils.initializeItemInfos(initialCapacity, out _itemInfos, out _sourceRangePositions); _thisAsSourceCollectionChangeProcessor = this; }
protected override void initializeFromSource() { int originalCount = _items.Count; if (_sourceInitialized) { int itemInfosCount = _itemInfos.Count; for (int index = 0; index < itemInfosCount; index++) { ItemInfo itemInfo = _itemInfos[index]; if (itemInfo.Source != null) { itemInfo.Source.CollectionChanged -= itemInfo.SourceNotifyCollectionChangedEventHandler; if (itemInfo.SourceAsINotifyPropertyChanged != null) itemInfo.SourceAsINotifyPropertyChanged.PropertyChanged -= itemInfo.SourcePropertyChangedEventHandler; } if (itemInfo.SourceScalar != null) itemInfo.SourceScalar.PropertyChanged -= itemInfo.SourceScalarPropertyChangedEventHandler; } Utils.initializeItemInfos( Utils.getCapacity(_sourcesScalar, _sources), out _itemInfos, out _sourceRangePositions); _sources.CollectionChanged -= handleSourcesCollectionChanged; if (_sourcesAsINotifyPropertyChanged != null) { _sourcesAsINotifyPropertyChanged.PropertyChanged -= ((ISourceIndexerPropertyTracker) this).HandleSourcePropertyChanged; _sourcesAsINotifyPropertyChanged = null; } _sourceInitialized = false; } Utils.changeSource(ref _sources, _sourcesScalar, _downstreamConsumedComputings, _consumers, this, ref _sourcesAsList, true); if (_sources != null && _isActive) { Utils.initializeFromHasChangeMarker( out _sourcesAsIHasChangeMarker, _sourcesAsList, ref _lastProcessedSourcesChangeMarker, ref _sourcesAsINotifyPropertyChanged, (ISourceIndexerPropertyTracker)this); int plainIndex = 0; int count = _sourcesAsList.Count; object[] sourcesCopy = new object[count]; _sourcesAsList.CopyTo(sourcesCopy, 0); for (int index = 0; index < count; index++) { object sourceItemObject = sourcesCopy[index]; IReadScalar<object> sourceItemScalar = sourceItemObject as IReadScalar<object>; IList sourceItem = sourceItemScalar != null ? (IList)sourceItemScalar.Value : (IList) sourceItemObject; int sourceItemCount = sourceItem?.Count ?? 0; ItemInfo itemInfo = _sourceRangePositions.Add(sourceItemCount); registerSourceItem(sourceItemObject, itemInfo); IList<TSourceItem> sourceCopy = itemInfo.SourceCopy; for (int sourceSourceIndex = 0; sourceSourceIndex < sourceItemCount; sourceSourceIndex++) { if (originalCount > plainIndex) // ReSharper disable once PossibleNullReferenceException _items[plainIndex++] = sourceCopy[sourceSourceIndex]; else // ReSharper disable once PossibleNullReferenceException _items.Insert(plainIndex++, sourceCopy[sourceSourceIndex]); } } for (int index = originalCount - 1; index >= plainIndex; index--) { _items.RemoveAt(index); } _sources.CollectionChanged += handleSourcesCollectionChanged; _sourceInitialized = true; } else { _items.Clear(); } reset(); }