Beispiel #1
0
 private void initializeOuterSourceScalar()
 {
     _outerSourceScalarPropertyChangedEventHandler     = handleSourceScalarValueChanged;
     _outerSourceScalarWeakPropertyChangedEventHandler =
         new WeakPropertyChangedEventHandler(_outerSourceScalarPropertyChangedEventHandler);
     _outerSourceScalar.PropertyChanged += _outerSourceScalarWeakPropertyChangedEventHandler.Handle;
 }
Beispiel #2
0
        private void initialize(IReadScalar <TResult> scalar, IDispatcher sourceDispatcher)
        {
            _scalar           = scalar;
            _sourceDispatcher = sourceDispatcher;

            void readAndSubscribe()
            {
                void setNewValue() => setValue(_scalar.Value);

                _destinationDispatcher.Invoke(setNewValue, this);

                _scalarPropertyChangedEventHandler     = handleScalarPropertyChanged;
                _scalarWeakPropertyChangedEventHandler =
                    new WeakPropertyChangedEventHandler(_scalarPropertyChangedEventHandler);
                _scalar.PropertyChanged += _scalarWeakPropertyChangedEventHandler.Handle;
            }

            if (_sourceDispatcher != null)
            {
                _sourceDispatcher.Invoke(readAndSubscribe, this);
            }
            else
            {
                readAndSubscribe();
            }
        }
 private void initializeIndexScalar()
 {
     _indexScalarPropertyChangedEventHandler     = handleIndexScalarValueChanged;
     _indexScalarWeakPropertyChangedEventHandler =
         new WeakPropertyChangedEventHandler(_indexScalarPropertyChangedEventHandler);
     _indexValueScalar.PropertyChanged += _indexScalarWeakPropertyChangedEventHandler.Handle;
     _index = _indexValueScalar.Value;
 }
 private Differing(
     IReadScalar <TResult> scalar)
 {
     _scalar = scalar;
     _scalarPropertyChangedEventHandler     = handleScalarPropertyChanged;
     _scalarWeakPropertyChangedEventHandler = new WeakPropertyChangedEventHandler(_scalarPropertyChangedEventHandler);
     _scalar.PropertyChanged += _scalarWeakPropertyChangedEventHandler.Handle;
 }
Beispiel #5
0
 private ScalarProcessingVoid(
     IReadScalar <TValue> scalar)
 {
     _scalar = scalar;
     _scalarPropertyChangedEventHandler     = handleScalarPropertyChanged;
     _scalarWeakPropertyChangedEventHandler = new WeakPropertyChangedEventHandler(_scalarPropertyChangedEventHandler);
     _scalar.PropertyChanged += _scalarWeakPropertyChangedEventHandler.Handle;
 }
 public Casting(
     IReadScalar <INotifyCollectionChanged> sourceScalar) : base(Utils.getCapacity(sourceScalar))
 {
     _sourceScalar = sourceScalar;
     _sourceScalarPropertyChangedEventHandler     = handleSourceScalarValueChanged;
     _sourceScalarWeakPropertyChangedEventHandler = new WeakPropertyChangedEventHandler(_sourceScalarPropertyChangedEventHandler);
     _sourceScalar.PropertyChanged += _sourceScalarWeakPropertyChangedEventHandler.Handle;
     initializeFromSource();
 }
 public PreviousTracking(
     IReadScalar <TResult> scalar)
 {
     _scalar = scalar;
     _value  = _scalar.Value;
     _scalarPropertyChangedEventHandler     = handleScalarPropertyChanged;
     _scalarWeakPropertyChangedEventHandler = new WeakPropertyChangedEventHandler(_scalarPropertyChangedEventHandler);
     _scalar.PropertyChanged += _scalarWeakPropertyChangedEventHandler.Handle;
 }
Beispiel #8
0
 private void initializeSeparatorScalar()
 {
     if (_separatorScalar != null)
     {
         _separatorScalarPropertyChangedEventHandler     = handleSeparatorScalarValueChanged;
         _separatorScalarWeakPropertyChangedEventHandler =
             new WeakPropertyChangedEventHandler(_separatorScalarPropertyChangedEventHandler);
         _separatorScalar.PropertyChanged += _separatorScalarWeakPropertyChangedEventHandler.Handle;
     }
 }
 private PropertyAccessing(
     IReadScalar <INotifyPropertyChanged> propertyHolderScalar)
 {
     _propertyHolderScalar = propertyHolderScalar;
     _propertyHolderScalarPropertyChangedEventHandler     = handlePropertyHolderScalarPropertyChanged;
     _propertyHolderScalarWeakPropertyChangedEventHandler =
         new WeakPropertyChangedEventHandler(_propertyHolderScalarPropertyChangedEventHandler);
     _propertyHolderScalar.PropertyChanged += _propertyHolderScalarWeakPropertyChangedEventHandler.Handle;
     _setValueAction = result => _propertyInfo.SetValue(_propertyHolder, result);
 }
        public Selecting(
            IReadScalar <INotifyCollectionChanged> sourceScalar,
            Expression <Func <TSourceItem, TResultItem> > selectorExpression) : this(selectorExpression, Utils.getCapacity(sourceScalar))
        {
            _sourceScalar = sourceScalar;
            _sourceScalarPropertyChangedEventHandler     = handleSourceScalarValueChanged;
            _sourceScalarWeakPropertyChangedEventHandler = new WeakPropertyChangedEventHandler(_sourceScalarPropertyChangedEventHandler);
            _sourceScalar.PropertyChanged += _sourceScalarWeakPropertyChangedEventHandler.Handle;

            initializeFromSource();
        }
        public AnyComputing(
            IReadScalar <INotifyCollectionChanged> sourceScalar,
            Expression <Func <TSourceItem, bool> > predicateExpression) : this(predicateExpression, Utils.getCapacity(sourceScalar))
        {
            _sourceScalar = sourceScalar;
            _sourceScalarPropertyChangedEventHandler     = handleSourceScalarValueChanged;
            _sourceScalarWeakPropertyChangedEventHandler = new WeakPropertyChangedEventHandler(_sourceScalarPropertyChangedEventHandler);
            _sourceScalar.PropertyChanged += _sourceScalarWeakPropertyChangedEventHandler.Handle;

            initializeFromSource();
        }
 public Differing(
     IReadScalar <TResult> scalar,
     IReadScalar <IEqualityComparer <TResult> > equalityComparerScalar) : this(scalar)
 {
     _equalityComparerScalarPropertyChangedEventHandler     = handleEqualityComparerScalarValueChanged;
     _equalityComparerScalarWeakPropertyChangedEventHandler =
         new WeakPropertyChangedEventHandler(_equalityComparerScalarPropertyChangedEventHandler);
     _equalityComparerScalar = equalityComparerScalar;
     _equalityComparerScalar.PropertyChanged += _equalityComparerScalarWeakPropertyChangedEventHandler.Handle;
     _equalityComparer = _equalityComparerScalar.Value ?? EqualityComparer <TResult> .Default;
 }
Beispiel #13
0
        public CollectionProcessingVoid(
            IReadScalar <INotifyCollectionChanged> sourceScalar,
            Action <TSourceItem, CollectionProcessingVoid <TSourceItem> > newItemProcessor  = null,
            Action <TSourceItem, CollectionProcessingVoid <TSourceItem> > oldItemProcessor  = null,
            Action <TSourceItem, CollectionProcessingVoid <TSourceItem> > moveItemProcessor = null) : this(newItemProcessor, oldItemProcessor, moveItemProcessor, Utils.getCapacity(sourceScalar))
        {
            _sourceScalar = sourceScalar;
            _sourceScalarPropertyChangedEventHandler     = handleSourceScalarValueChanged;
            _sourceScalarWeakPropertyChangedEventHandler = new WeakPropertyChangedEventHandler(_sourceScalarPropertyChangedEventHandler);
            _sourceScalar.PropertyChanged += _sourceScalarWeakPropertyChangedEventHandler.Handle;

            initializeFromSource(null, null);
        }
Beispiel #14
0
        public Concatenating(
            IReadScalar <INotifyCollectionChanged> sourcesScalar) : base(calculateCapacity(sourcesScalar.Value))
        {
            int capacity = Utils.getCapacity(sourcesScalar);

            _itemInfos            = new List <ItemInfo>(capacity);
            _sourceRangePositions = new RangePositions <ItemInfo>(_itemInfos);

            _sourcesScalar = sourcesScalar;
            _sourcesScalarPropertyChangedEventHandler     = handleSourcesScalarValueChanged;
            _sourcesScalarWeakPropertyChangedEventHandler = new WeakPropertyChangedEventHandler(_sourcesScalarPropertyChangedEventHandler);
            _sourcesScalar.PropertyChanged += _sourcesScalarWeakPropertyChangedEventHandler.Handle;
            initializeFromSources();
        }
Beispiel #15
0
 private void initializeComparerScalar()
 {
     if (_comparerScalar != null)
     {
         _comparerScalarPropertyChangedEventHandler     = handleComparerScalarValueChanged;
         _comparerScalarWeakPropertyChangedEventHandler =
             new WeakPropertyChangedEventHandler(_comparerScalarPropertyChangedEventHandler);
         _comparerScalar.PropertyChanged += _comparerScalarWeakPropertyChangedEventHandler.Handle;
         _comparer = _comparerScalar.Value ?? Comparer <TSourceItem> .Default;
     }
     else
     {
         _comparer = Comparer <TSourceItem> .Default;
     }
 }
Beispiel #16
0
        private void initialize(IReadScalar <INotifyCollectionChanged> sourceScalar, IDispatcher sourceDispatcher)
        {
            _sourceDispatcher = sourceDispatcher;
            _sourceScalar     = sourceScalar;
            _sourceScalarPropertyChangedEventHandler     = handleSourceScalarValueChanged;
            _sourceScalarWeakPropertyChangedEventHandler =
                new WeakPropertyChangedEventHandler(_sourceScalarPropertyChangedEventHandler);
            _sourceScalar.PropertyChanged += _sourceScalarWeakPropertyChangedEventHandler.Handle;

            if (_sourceDispatcher != null)
            {
                _sourceDispatcher.Invoke(initializeFromSource, this);
            }
            else
            {
                initializeFromSource();
            }
        }
Beispiel #17
0
        private void initializeFromSources()
        {
            int originalCount = _items.Count;

            if (_sourcesNotifyCollectionChangedEventHandler != null)
            {
                int itemInfosCount = _itemInfos.Count;
                for (int index = 0; index < itemInfosCount; index++)
                {
                    ItemInfo itemInfo = _itemInfos[index];
                    if (itemInfo.Source != null)
                    {
                        itemInfo.Source.CollectionChanged -=
                            itemInfo.SourceWeakNotifyCollectionChangedEventHandler.Handle;
                    }
                }

                int capacity = _sourcesScalar != null?Utils.getCapacity(_sourcesScalar) : Utils.getCapacity(_sources);

                _itemInfos            = new List <ItemInfo>(capacity);
                _sourceRangePositions = new RangePositions <ItemInfo>(_itemInfos);

                _sources.CollectionChanged -= _sourcesWeakNotifyCollectionChangedEventHandler.Handle;
                _sourcesNotifyCollectionChangedEventHandler     = null;
                _sourcesWeakNotifyCollectionChangedEventHandler = null;
            }

            if (_sourcesAsINotifyPropertyChanged != null)
            {
                _sourcesAsINotifyPropertyChanged.PropertyChanged -=
                    _sourcesWeakPropertyChangedEventHandler.Handle;

                _sourcesAsINotifyPropertyChanged        = null;
                _sourcesPropertyChangedEventHandler     = null;
                _sourcesWeakPropertyChangedEventHandler = null;
            }

            if (_sourcesScalar != null)
            {
                _sources = _sourcesScalar.Value;
            }
            _sourcesAsList = (IList)_sources;

            if (_sources != null)
            {
                _sourcesAsIHasChangeMarker = _sourcesAsList as IHasChangeMarker;

                if (_sourcesAsIHasChangeMarker != null)
                {
                    _lastProcessedSourcesChangeMarker = _sourcesAsIHasChangeMarker.ChangeMarker;
                }
                else
                {
                    _sourcesAsINotifyPropertyChanged = (INotifyPropertyChanged)_sourcesAsList;

                    _sourcesPropertyChangedEventHandler = (sender, args) =>
                    {
                        if (args.PropertyName == "Item[]")
                        {
                            _indexerPropertyChangedEventRaised = true;                                                        // ObservableCollection raises this before CollectionChanged event raising
                        }
                    };

                    _sourcesWeakPropertyChangedEventHandler =
                        new WeakPropertyChangedEventHandler(_sourcesPropertyChangedEventHandler);

                    _sourcesAsINotifyPropertyChanged.PropertyChanged +=
                        _sourcesWeakPropertyChangedEventHandler.Handle;
                }


                int plainIndex = 0;
                int count      = _sourcesAsList.Count;
                for (int index = 0; index < count; index++)
                {
                    object sourceItemObject = _sourcesAsList[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);

                    for (int sourceSourceIndex = 0; sourceSourceIndex < sourceItemCount; sourceSourceIndex++)
                    {
                        if (originalCount > plainIndex)
                        {
                            // ReSharper disable once PossibleNullReferenceException
                            _items[plainIndex++] = (TSourceItem)sourceItem[sourceSourceIndex];
                        }
                        else
                        {
                            // ReSharper disable once PossibleNullReferenceException
                            _items.Insert(plainIndex++, (TSourceItem)sourceItem[sourceSourceIndex]);
                        }
                    }
                }

                for (int index = originalCount - 1; index >= plainIndex; index--)
                {
                    _items.RemoveAt(index);
                }

                _sourcesNotifyCollectionChangedEventHandler     = handleSourcesCollectionChanged;
                _sourcesWeakNotifyCollectionChangedEventHandler =
                    new WeakNotifyCollectionChangedEventHandler(_sourcesNotifyCollectionChangedEventHandler);

                _sources.CollectionChanged += _sourcesWeakNotifyCollectionChangedEventHandler.Handle;
            }
            else
            {
                _items.Clear();
            }

            reset();
        }
        private void registerPropertyHolder(INotifyPropertyChanged propertyHolder)
        {
            if (_propertyHolderWeakPropertyChangedEventHandler != null)
            {
                _propertyHolder.PropertyChanged -= _propertyHolderWeakPropertyChangedEventHandler.Handle;
                _propertyHolderWeakPropertyChangedEventHandler = null;
                _propertyHolderPropertyChangedEventHandler     = null;
            }

            void getPropertyInfo(PropertyInfo[] propertyInfos)
            {
                for (int i = 0; i < propertyInfos.Length; i++)
                {
                    PropertyInfo propertyInfo = propertyInfos[i];
                    if (_propertyInfoPredicate(propertyInfo))
                    {
                        _propertyInfo = propertyInfo;
                        break;
                    }
                }
            }

            _propertyInfo   = null;
            _propertyHolder = propertyHolder;

            if (_propertyHolder == null)
            {
                setValue(_defaultValue);
                return;
            }

            _propertyHolderType = _propertyHolder.GetType();

            switch (_propertyInfoGettingType)
            {
            case PropertyInfoGettingType.PropertyName:
                _propertyInfo = _propertyHolderType.GetProperty(_propertyName);
                break;

            case PropertyInfoGettingType.BindingAttr:
                _propertyInfo = _propertyHolderType.GetProperty(_propertyName, _bindingAttr);
                break;

            case PropertyInfoGettingType.Binder:
                _propertyInfo = _propertyHolderType.GetProperty(_propertyName, _bindingAttr, _binder, _returnType, _types, _modifiers);
                break;

            case PropertyInfoGettingType.ReturnType:
                _propertyInfo = _propertyHolderType.GetProperty(_propertyName, _returnType);
                break;

            case PropertyInfoGettingType.Types:
                _propertyInfo = _propertyHolderType.GetProperty(_propertyName, _returnType, _types);
                break;

            case PropertyInfoGettingType.Modifiers:
                _propertyInfo = _propertyHolderType.GetProperty(_propertyName, _returnType, _types, _modifiers);
                break;

            case PropertyInfoGettingType.PropertyInfoPredicate:
                getPropertyInfo(_propertyHolderType.GetProperties());
                break;

            case PropertyInfoGettingType.PropertyInfoPredicateBindingAttr:
                getPropertyInfo(_propertyHolderType.GetProperties(_bindingAttr));
                break;
            }

            if (_propertyInfo == null)
            {
                throw new ObservableComputationsException(this, "Cannot obtain propertyInfo");
            }

            _propertyHolderPropertyChangedEventHandler     = handlePropertyHolderPropertyChanged;
            _propertyHolderWeakPropertyChangedEventHandler =
                new WeakPropertyChangedEventHandler(_propertyHolderPropertyChangedEventHandler);
            _propertyHolder.PropertyChanged += _propertyHolderWeakPropertyChangedEventHandler.Handle;

            setValue((TResult)_propertyInfo.GetValue(_propertyHolder));
        }
Beispiel #19
0
        private void initializeFromSources()
        {
            if (_outerSourceNotifyCollectionChangedEventHandler != null)
            {
                _outerSource.CollectionChanged -= _outerSourceWeakNotifyCollectionChangedEventHandler.Handle;
                _outerSourceNotifyCollectionChangedEventHandler     = null;
                _outerSourceWeakNotifyCollectionChangedEventHandler = null;
            }

            if (_innerSourceNotifyCollectionChangedEventHandler != null)
            {
                _innerSource.CollectionChanged -= _innerSourceWeakNotifyCollectionChangedEventHandler.Handle;
                _innerSourceNotifyCollectionChangedEventHandler     = null;
                _innerSourceWeakNotifyCollectionChangedEventHandler = null;
            }

            if (_innerSourceAsINotifyPropertyChanged != null)
            {
                _innerSourceAsINotifyPropertyChanged.PropertyChanged -=
                    _innerSourceWeakPropertyChangedEventHandler.Handle;

                _innerSourceAsINotifyPropertyChanged        = null;
                _innerSourcePropertyChangedEventHandler     = null;
                _innerSourceWeakPropertyChangedEventHandler = null;
            }

            if (_outerSourceAsINotifyPropertyChanged != null)
            {
                _outerSourceAsINotifyPropertyChanged.PropertyChanged -=
                    _outerSourceWeakPropertyChangedEventHandler.Handle;

                _outerSourceAsINotifyPropertyChanged        = null;
                _outerSourcePropertyChangedEventHandler     = null;
                _outerSourceWeakPropertyChangedEventHandler = null;
            }


            if (_outerSource != null || _innerSource != null)
            {
                baseClearItems();
            }

            if (_outerSourceScalar != null)
            {
                _outerSource = _outerSourceScalar.Value;
            }
            _outerSourceAsList = (IList <TOuterSourceItem>)_outerSource;

            if (_innerSourceScalar != null)
            {
                _innerSource = _innerSourceScalar.Value;
            }
            _innerSourceAsList = (IList <TInnerSourceItem>)_innerSource;

            if (_outerSource != null && _innerSource != null)
            {
                _outerSourceAsObservableCollectionWithChangeMarker = _outerSourceAsList as ObservableCollectionWithChangeMarker <TOuterSourceItem>;

                if (_outerSourceAsObservableCollectionWithChangeMarker != null)
                {
                    _lastProcessedOuterSourceChangeMarker = _outerSourceAsObservableCollectionWithChangeMarker.ChangeMarkerField;
                }
                else
                {
                    _outerSourceAsINotifyPropertyChanged = (INotifyPropertyChanged)_outerSource;

                    _outerSourcePropertyChangedEventHandler = (sender, args) =>
                    {
                        if (args.PropertyName == "Item[]")
                        {
                            _outerSourceIndexerPropertyChangedEventRaised = true;                                                        // ObservableCollection raises this before CollectionChanged event raising
                        }
                    };

                    _outerSourceWeakPropertyChangedEventHandler =
                        new WeakPropertyChangedEventHandler(_outerSourcePropertyChangedEventHandler);

                    _outerSourceAsINotifyPropertyChanged.PropertyChanged +=
                        _outerSourceWeakPropertyChangedEventHandler.Handle;
                }


                _innerSourceAsObservableCollectionWithChangeMarker = _innerSourceAsList as ObservableCollectionWithChangeMarker <TInnerSourceItem>;

                if (_innerSourceAsObservableCollectionWithChangeMarker != null)
                {
                    _lastProcessedInnerSourceChangeMarker = _innerSourceAsObservableCollectionWithChangeMarker.ChangeMarkerField;
                }
                else
                {
                    _innerSourceAsINotifyPropertyChanged = (INotifyPropertyChanged)_innerSource;

                    _innerSourcePropertyChangedEventHandler = (sender, args) =>
                    {
                        if (args.PropertyName == "Item[]")
                        {
                            _innerSourceIndexerPropertyChangedEventRaised = true;                                                        // ObservableCollection raises this before CollectionChanged event raising
                        }
                    };

                    _innerSourceWeakPropertyChangedEventHandler =
                        new WeakPropertyChangedEventHandler(_innerSourcePropertyChangedEventHandler);

                    _innerSourceAsINotifyPropertyChanged.PropertyChanged +=
                        _innerSourceWeakPropertyChangedEventHandler.Handle;
                }


                // ReSharper disable once PossibleNullReferenceException
                int outerSourceCount = _outerSourceAsList.Count;
                // ReSharper disable once PossibleNullReferenceException
                int innerSourceCount = _innerSourceAsList.Count;
                int baseIndex        = 0;
                for (int outerSourceIndex = 0; outerSourceIndex < outerSourceCount; outerSourceIndex++)
                {
                    TOuterSourceItem sourceOuterItem = _outerSourceAsList[outerSourceIndex];
                    for (int innerSourceIndex = 0; innerSourceIndex < innerSourceCount; innerSourceIndex++)
                    {
                        TInnerSourceItem sourceInnerItem = _innerSourceAsList[innerSourceIndex];
                        JoinPair <TOuterSourceItem, TInnerSourceItem> joinPair = new JoinPair <TOuterSourceItem, TInnerSourceItem>(
                            sourceOuterItem, sourceInnerItem);
                        baseInsertItem(baseIndex + innerSourceIndex, joinPair);
                    }

                    baseIndex = baseIndex + innerSourceCount;
                }

                _outerSourceNotifyCollectionChangedEventHandler     = handleOuterSourceCollectionChanged;
                _outerSourceWeakNotifyCollectionChangedEventHandler =
                    new WeakNotifyCollectionChangedEventHandler(_outerSourceNotifyCollectionChangedEventHandler);

                _outerSource.CollectionChanged += _outerSourceWeakNotifyCollectionChangedEventHandler.Handle;

                _innerSourceNotifyCollectionChangedEventHandler     = handleInnerSourceCollectionChanged;
                _innerSourceWeakNotifyCollectionChangedEventHandler =
                    new WeakNotifyCollectionChangedEventHandler(_innerSourceNotifyCollectionChangedEventHandler);

                _innerSource.CollectionChanged += _innerSourceWeakNotifyCollectionChangedEventHandler.Handle;
            }
        }
Beispiel #20
0
        private void initialize(Expression <Func <TResult> > propertyExpression)
        {
            _propertyExpression = propertyExpression;

            MemberExpression memberExpression = (MemberExpression)propertyExpression.Body;

            PropertyInfo      propertyInfo = (PropertyInfo)((MemberExpression)propertyExpression.Body).Member;
            PropertyAccessors propertyAcessors;

            if (!_propertyAccessors.TryGetValue(propertyInfo, out propertyAcessors))
            {
                ParameterExpression valueParameterExpression  = Expression.Parameter(typeof(TResult));
                ParameterExpression holderParameterExpression = Expression.Parameter(typeof(THolder));
                var setter = Expression.Lambda <Action <THolder, TResult> >(
                    Expression.Assign(Expression.Property(holderParameterExpression, propertyInfo), valueParameterExpression),
                    holderParameterExpression, valueParameterExpression).Compile();

                var getter = Expression.Lambda <Func <THolder, TResult> >(
                    Expression.Property(holderParameterExpression, propertyInfo),
                    holderParameterExpression).Compile();

                propertyAcessors = new PropertyAccessors(getter, setter);
                _propertyAccessors.TryAdd(propertyInfo, propertyAcessors);
            }

            _getter = propertyAcessors.Getter;
            _setter = propertyAcessors.Setter;

            _propertyHolder = (THolder)((ConstantExpression)memberExpression.Expression).Value;

            _propertyHolderPropertyChangedEventHandler     = handlePropertyHolderPropertyChanged;
            _propertyHolderWeakPropertyChangedEventHandler =
                new WeakPropertyChangedEventHandler(_propertyHolderPropertyChangedEventHandler);


            void readAndSubscribe()
            {
                getValue();

                void raiseValuePropertyChanged()
                {
                    PropertyChanged?.Invoke(this, Utils.ValuePropertyChangedEventArgs);
                }

                _propertyHolder.PropertyChanged += _propertyHolderWeakPropertyChangedEventHandler.Handle;

                _destinationDispatcher.Invoke(raiseValuePropertyChanged, this);
            }

            if (_sourceDispatcher != null)
            {
                if (_sourceDispatcher != null)
                {
                    _sourceDispatcher.Invoke(readAndSubscribe, this);
                }
                else
                {
                    _propertySourceDispatcher.Invoke(readAndSubscribe, this, true, null);
                }
            }
            else
            {
                readAndSubscribe();
            }

            if (Configuration.SaveInstantiatingStackTrace)
            {
                _instantiatingStackTrace = Environment.StackTrace;
            }
        }
Beispiel #21
0
        private void initializeFromSource()
        {
            int originalCount = _items.Count;

            if (_sourceWeakPropertyChangedEventHandler == null)
            {
                _sourceAsINotifyPropertyChanged = (INotifyPropertyChanged)_sourceAsList;

                _sourcePropertyChangedEventHandler = (sender, args) =>
                {
                    if (args.PropertyName == "Item[]")
                    {
                        _indexerPropertyChangedEventRaised = true;                                                    // ObservableCollection raises this before CollectionChanged event raising
                    }
                };

                _sourceWeakPropertyChangedEventHandler = new WeakPropertyChangedEventHandler(_sourcePropertyChangedEventHandler);

                _sourceAsINotifyPropertyChanged.PropertyChanged += _sourceWeakPropertyChangedEventHandler.Handle;
            }

            int count = _sourceAsList.Count;

            if (count > 0)
            {
                int sourceIndex;
                for (sourceIndex = 0; sourceIndex < count; sourceIndex++)
                {
                    if (originalCount > sourceIndex)
                    {
                        _items[sourceIndex] = _sourceAsList[sourceIndex];
                    }
                    else
                    {
                        _items.Insert(sourceIndex, _sourceAsList[sourceIndex]);
                    }
                }

                for (int index = originalCount - 1; index >= sourceIndex; index--)
                {
                    _items.RemoveAt(index);
                }
            }
            else
            {
                _items.Clear();
            }

            if (_sourceWeakNotifyCollectionChangedEventHandler == null)
            {
                _sourceNotifyCollectionChangedEventHandler     = handleSourceCollectionChanged;
                _sourceWeakNotifyCollectionChangedEventHandler =
                    new WeakNotifyCollectionChangedEventHandler(_sourceNotifyCollectionChangedEventHandler);

                _source.CollectionChanged += _sourceWeakNotifyCollectionChangedEventHandler.Handle;
            }

            ChangeMarkerField = !ChangeMarkerField;
            this.CheckReentrancy();
            this.OnPropertyChanged(Utils.CountPropertyChangedEventArgs);
            this.OnPropertyChanged(Utils.IndexerPropertyChangedEventArgs);
            this.OnCollectionChanged(Utils.ResetNotifyCollectionChangedEventArgs);
        }
Beispiel #22
0
        private void initializeFromSource()
        {
            if (_sourceNotifyCollectionChangedEventHandler != null)
            {
                _valueStringBuilder.Clear();

                int capacity = _sourceScalar != null?Utils.getCapacity(_sourceScalar) : Utils.getCapacity(_source);

                _resultRangePositions = new RangePositions <RangePosition>(new List <RangePosition>(capacity * 2));

                _source.CollectionChanged -= _sourceWeakNotifyCollectionChangedEventHandler.Handle;
                _sourceNotifyCollectionChangedEventHandler     = null;
                _sourceWeakNotifyCollectionChangedEventHandler = null;
                setValue(String.Empty);
            }

            if (_sourceAsINotifyPropertyChanged != null)
            {
                _sourceAsINotifyPropertyChanged.PropertyChanged -=
                    _sourceWeakPropertyChangedEventHandler.Handle;

                _sourceAsINotifyPropertyChanged        = null;
                _sourcePropertyChangedEventHandler     = null;
                _sourceWeakPropertyChangedEventHandler = null;
            }

            if (_sourceScalar != null)
            {
                _source = _sourceScalar.Value;
            }
            _sourceAsList = (IList <string>)_source;

            if (_source != null)
            {
                _sourceAsObservableCollectionWithChangeMarker = _sourceAsList as ObservableCollectionWithChangeMarker <string>;

                if (_sourceAsObservableCollectionWithChangeMarker != null)
                {
                    _lastProcessedSourceChangeMarker = _sourceAsObservableCollectionWithChangeMarker.ChangeMarkerField;
                }
                else
                {
                    _sourceAsINotifyPropertyChanged = (INotifyPropertyChanged)_sourceAsList;

                    _sourcePropertyChangedEventHandler = (sender, args) =>
                    {
                        if (args.PropertyName == "Item[]")
                        {
                            _indexerPropertyChangedEventRaised =
                                true;                                 // ObservableCollection raises this before CollectionChanged event raising
                        }
                    };

                    _sourceWeakPropertyChangedEventHandler =
                        new WeakPropertyChangedEventHandler(_sourcePropertyChangedEventHandler);

                    _sourceAsINotifyPropertyChanged.PropertyChanged += _sourceWeakPropertyChangedEventHandler.Handle;
                }

                _sourceNotifyCollectionChangedEventHandler     = handleSourceCollectionChanged;
                _sourceWeakNotifyCollectionChangedEventHandler =
                    new WeakNotifyCollectionChangedEventHandler(_sourceNotifyCollectionChangedEventHandler);
                _source.CollectionChanged += _sourceWeakNotifyCollectionChangedEventHandler.Handle;

                recalculateValue();
            }
            else
            {
                _valueStringBuilder.Clear();
                setValue(String.Empty);
            }
        }
        private void initializeFromSource()
        {
            if (_sourceNotifyCollectionChangedEventHandler != null)
            {
                _source.CollectionChanged -= _sourceWeakNotifyCollectionChangedEventHandler.Handle;
                _sourceNotifyCollectionChangedEventHandler     = null;
                _sourceWeakNotifyCollectionChangedEventHandler = null;
            }

            if (_sourceAsINotifyPropertyChanged != null)
            {
                _sourceAsINotifyPropertyChanged.PropertyChanged -=
                    _sourceWeakPropertyChangedEventHandler.Handle;

                _sourceAsINotifyPropertyChanged        = null;
                _sourcePropertyChangedEventHandler     = null;
                _sourceWeakPropertyChangedEventHandler = null;
            }

            if (_sourceScalar != null)
            {
                _source = _sourceScalar.Value;
            }
            _sourceAsList = (IList <TSourceItem>)_source;

            if (_source != null)
            {
                _sourceAsObservableCollectionWithChangeMarker = _sourceAsList as ObservableCollectionWithChangeMarker <TSourceItem>;

                if (_sourceAsObservableCollectionWithChangeMarker != null)
                {
                    _lastProcessedSourceChangeMarker = _sourceAsObservableCollectionWithChangeMarker.ChangeMarkerField;
                }
                else
                {
                    _sourceAsINotifyPropertyChanged = (INotifyPropertyChanged)_sourceAsList;

                    _sourcePropertyChangedEventHandler = (sender, args) =>
                    {
                        if (args.PropertyName == "Item[]")
                        {
                            _indexerPropertyChangedEventRaised =
                                true;                                 // ObservableCollection raises this before CollectionChanged event raising
                        }
                    };

                    _sourceWeakPropertyChangedEventHandler =
                        new WeakPropertyChangedEventHandler(_sourcePropertyChangedEventHandler);

                    _sourceAsINotifyPropertyChanged.PropertyChanged += _sourceWeakPropertyChangedEventHandler.Handle;
                }

                _sourceNotifyCollectionChangedEventHandler     = handleSourceCollectionChanged;
                _sourceWeakNotifyCollectionChangedEventHandler =
                    new WeakNotifyCollectionChangedEventHandler(_sourceNotifyCollectionChangedEventHandler);

                _source.CollectionChanged += _sourceWeakNotifyCollectionChangedEventHandler.Handle;
            }

            recalculateValue();
        }
Beispiel #24
0
        private void initializeFromSource()
        {
            int originalCount = _items.Count;

            if (_sourceNotifyCollectionChangedEventHandler != null)
            {
                if (_destinationDispatcher != null)
                {
                    _destinationDispatcher.Invoke(baseClearItems, this);
                }
                else
                {
                    _collectionDestinationDispatcher.Invoke(baseClearItems, this, NotifyCollectionChangedAction.Reset, null, null, 0, 0);
                }

                _source.CollectionChanged -= _sourceWeakNotifyCollectionChangedEventHandler.Handle;
                _sourceNotifyCollectionChangedEventHandler     = null;
                _sourceWeakNotifyCollectionChangedEventHandler = null;
            }

            if (_sourceAsINotifyPropertyChanged != null)
            {
                _sourceAsINotifyPropertyChanged.PropertyChanged -=
                    _sourceWeakPropertyChangedEventHandler.Handle;

                _sourceAsINotifyPropertyChanged        = null;
                _sourcePropertyChangedEventHandler     = null;
                _sourceWeakPropertyChangedEventHandler = null;
            }

            if (_sourceScalar != null)
            {
                _source = _sourceScalar.Value;
            }
            _sourceAsList = _source as IList <TSourceItem>;

            if (_sourceAsList != null)
            {
                _sourceAsIHasChangeMarker = _sourceAsList as IHasChangeMarker;

                if (_sourceAsIHasChangeMarker != null)
                {
                    _lastProcessedSourceChangeMarker = _sourceAsIHasChangeMarker.ChangeMarker;
                }
                else
                {
                    _sourceAsINotifyPropertyChanged = (INotifyPropertyChanged)_sourceAsList;

                    _sourcePropertyChangedEventHandler = (sender1, args1) =>
                    {
                        if (args1.PropertyName == "Item[]")
                        {
                            _indexerPropertyChangedEventRaised =
                                true;                                 // ObservableCollection raises this before CollectionChanged event raising
                        }
                    };

                    _sourceWeakPropertyChangedEventHandler =
                        new WeakPropertyChangedEventHandler(_sourcePropertyChangedEventHandler);

                    _sourceAsINotifyPropertyChanged.PropertyChanged += _sourceWeakPropertyChangedEventHandler.Handle;
                }

                int count = _sourceAsList.Count;
                int sourceIndex;
                for (sourceIndex = 0; sourceIndex < count; sourceIndex++)
                {
                    if (originalCount > sourceIndex)
                    {
                        _items[sourceIndex] = _sourceAsList[sourceIndex];
                    }
                    else
                    {
                        _items.Insert(sourceIndex, _sourceAsList[sourceIndex]);
                    }
                }

                for (int index = originalCount - 1; index >= sourceIndex; index--)
                {
                    _items.RemoveAt(index);
                }

                _sourceNotifyCollectionChangedEventHandler     = handleSourceCollectionChanged;
                _sourceWeakNotifyCollectionChangedEventHandler =
                    new WeakNotifyCollectionChangedEventHandler(_sourceNotifyCollectionChangedEventHandler);
                _source.CollectionChanged += _sourceWeakNotifyCollectionChangedEventHandler.Handle;
            }
            else
            {
                _items.Clear();
            }

            if (_destinationDispatcher != null)
            {
                _destinationDispatcher.Invoke(reset, this);
            }
            else
            {
                _collectionDestinationDispatcher.Invoke(reset, this, NotifyCollectionChangedAction.Reset, null, null, 0, 0);
            }
        }