/// <summary> /// Gets or sets the element at the specified index. /// </summary> /// <param name="index">The zero-based index of the element to get or set.</param> /// <returns>The element at the specified index.</returns> /// <exception cref="ArgumentOutOfRangeException">index is not a valid index in the <see cref="ObservableCollection{T}"/>.</exception> /// <exception cref="NotSupportedException">The property is set and the <see cref="ObservableCollection{T}"/> is read-only.</exception> public T this[int index] { get { if (index >= 0 && index < this.innerList.Count) { this.atom.ReportObserved(); } return(this.innerList[index]); } set { if (index >= 0 && index < this.innerList.Count && !this.IsReadOnly) { this.atom.CheckIfStateModificationsAreAllowed(); var oldValue = this.innerList[index]; var changeEventArgs = new ObservableCollectionChangeEventArgs <T>() { Cancel = false, Context = this, NewValue = value, OldValue = oldValue, }; this.InterceptChange(changeEventArgs); if (changeEventArgs.Cancel || !changeEventArgs.Changed) { return; } var newValue = this.enhancer.Enhance(changeEventArgs.NewValue, oldValue, this.Name); if (!Equals(oldValue, newValue)) { if (newValue is IReactiveObject reactiveObject) { if (reactiveObject.SharedState != this.SharedState) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.DifferentSharedStates, this.Name)); } } this.innerList[index] = newValue; this.NotifyArrayChildUpdate(index, newValue, oldValue); } } else { // this will trap this.innerList[index] = value; } } }
/// <summary> /// Gets or sets the element at the specified index. /// </summary> /// <param name="index">The zero-based index of the element to get or set.</param> /// <returns>The element at the specified index.</returns> /// <exception cref="ArgumentOutOfRangeException">index is not a valid index in the <see cref="ObservableCollection{T}"/>.</exception> /// <exception cref="NotSupportedException">The property is set and the <see cref="ObservableCollection{T}"/> is read-only.</exception> public T this[int index] { get { if (index >= 0 && index < this.innerList.Count) { this.atom.ReportObserved(); } return(this.innerList[index]); } set { if (index >= 0 && index < this.innerList.Count && !this.IsReadOnly) { this.atom.CheckIfStateModificationsAreAllowed(); var oldValue = this.innerList[index]; var changeEventArgs = new ObservableCollectionChangeEventArgs <T>() { Cancel = false, Context = this, NewValue = value, OldValue = oldValue, }; this.InterceptChange(changeEventArgs); if (changeEventArgs.Cancel || !changeEventArgs.Changed) { return; } var newValue = this.enhancer.Enhance(changeEventArgs.NewValue, oldValue, this.Name); if (!Equals(oldValue, newValue)) { this.innerList[index] = newValue; this.NotifyArrayChildUpdate(index, newValue, oldValue); } } else { // this will trap this.innerList[index] = value; } } }