public void RemoveAt(int index) { _inner.MarkChange(); if ((index < 0) || (index >= _inner.combinedValues.Count)) { GlobalDebug.WriteLineIf(GlobalDebug.Warn, "PrincipalValueCollection", "RemoveAt({0}): out of range (count={1})", index, _inner.combinedValues.Count); throw new ArgumentOutOfRangeException("index"); } TrackedCollection <T> .ValueEl el = _inner.combinedValues[index]; if (el.isInserted) { // We're removing an inserted value. GlobalDebug.WriteLineIf(GlobalDebug.Info, "PrincipalValueCollection", "RemoveAt({0}): removing inserted", index); _inner.combinedValues.RemoveAt(index); } else { // We're removing an original value. GlobalDebug.WriteLineIf(GlobalDebug.Info, "PrincipalValueCollection", "RemoveAt({0}): removing original", index); Pair <T, T> pair = _inner.combinedValues[index].originalValue; _inner.combinedValues.RemoveAt(index); _inner.removedValues.Add(pair.Left); } }
public bool MoveNext() { this.CheckDisposed(); this.CheckChanged(); if (!this.endReached) { if (this.enumerator == null) { this.enumerator = this.combinedValues.GetEnumerator(); } bool flag = this.enumerator.MoveNext(); if (!flag) { this.endReached = true; } else { TrackedCollection <T> .ValueEl current = (TrackedCollection <T> .ValueEl) this.enumerator.Current; if (!current.isInserted) { this.current = current.originalValue.Right; } else { this.current = current.insertedValue; } } return(flag); } else { return(false); } }
internal TrackedCollectionEnumerator(string outerClassName, TrackedCollection <T> trackedCollection, List <TrackedCollection <T> .ValueEl> combinedValues) { this.creationTime = DateTime.UtcNow; this.outerClassName = outerClassName; this.trackedCollection = trackedCollection; this.combinedValues = combinedValues; }
public T this[int index] { get { if ((index < 0) || (index >= _inner.combinedValues.Count)) { GlobalDebug.WriteLineIf(GlobalDebug.Warn, "PrincipalValueCollection", "this[{0}].get: out of range (count={1})", index, _inner.combinedValues.Count); throw new ArgumentOutOfRangeException("index"); } TrackedCollection <T> .ValueEl el = _inner.combinedValues[index]; if (el.isInserted) { GlobalDebug.WriteLineIf(GlobalDebug.Info, "PrincipalValueCollection", "this[{0}].get: is inserted {1}", index, el.insertedValue); return(el.insertedValue); } else { GlobalDebug.WriteLineIf(GlobalDebug.Info, "PrincipalValueCollection", "this[{0}].get: is original {1}", index, el.originalValue.Right); return(el.originalValue.Right); // Right == current value } } set { _inner.MarkChange(); if ((index < 0) || (index >= _inner.combinedValues.Count)) { GlobalDebug.WriteLineIf(GlobalDebug.Warn, "PrincipalValueCollection", "this[{0}].set: out of range (count={1})", index, _inner.combinedValues.Count); throw new ArgumentOutOfRangeException("index"); } if (value == null) { throw new ArgumentNullException("value"); } TrackedCollection <T> .ValueEl el = _inner.combinedValues[index]; if (el.isInserted) { GlobalDebug.WriteLineIf(GlobalDebug.Info, "PrincipalValueCollection", "this[{0}].set: is inserted {1}", index, value); el.insertedValue = value; } else { GlobalDebug.WriteLineIf(GlobalDebug.Info, "PrincipalValueCollection", "this[{0}].set: is original {1}", index, value); el.originalValue.Right = value; } } }
public void Insert(int index, T value) { _inner.MarkChange(); if (value == null) { throw new ArgumentNullException("value"); } if ((index < 0) || (index > _inner.combinedValues.Count)) { GlobalDebug.WriteLineIf(GlobalDebug.Warn, "PrincipalValueCollection", "Insert({0}): out of range (count={1})", index, _inner.combinedValues.Count); throw new ArgumentOutOfRangeException("index"); } TrackedCollection <T> .ValueEl el = new TrackedCollection <T> .ValueEl(); el.isInserted = true; el.insertedValue = value; _inner.combinedValues.Insert(index, el); }
// // Load/Store implementation // internal void Load(List <T> values) { GlobalDebug.WriteLineIf(GlobalDebug.Info, "PrincipalValueCollection", "Load, count={0}", values.Count); // To support reload _inner.combinedValues.Clear(); _inner.removedValues.Clear(); foreach (T value in values) { // If T was a mutable reference type, would need to make a copy of value // for the left-side of the Pair, so that changes to the value in the // right-side wouldn't also change the left-side value (due to aliasing). // However, we constrain T to be either a value type or a immutable ref type (e.g., string) // to avoid this problem. TrackedCollection <T> .ValueEl el = new TrackedCollection <T> .ValueEl(); el.isInserted = false; el.originalValue = new Pair <T, T>(value, value); _inner.combinedValues.Add(el); } }
internal PrincipalValueCollection() { this.inner = new TrackedCollection <T>(); }
internal ValueCollectionEnumerator(TrackedCollection <T> trackingList, List <TrackedCollection <T> .ValueEl> combinedValues) { this.inner = new TrackedCollectionEnumerator <T>("ValueCollectionEnumerator", trackingList, combinedValues); }