protected override IEnumerable <CollectionOperation <TAdaptee> > Enumerate() { foreach (var update in _adaptee.Operations()) { switch (update.Type) { case CollectionOperationType.Add: var added = _state.Get(update.Item, _removedOnChange); yield return(CollectionOperation <TAdaptee> .OnAdd(added)); break; case CollectionOperationType.Remove: var removed = _state.Get(update.Item, _removedOnChange); yield return(CollectionOperation <TAdaptee> .OnRemove(removed)); break; case CollectionOperationType.Clear: yield return(CollectionOperation <TAdaptee> .OnClear()); break; default: throw new ArgumentOutOfRangeException(); } } }
public override void OnNext(IChange <CollectionOperation <T> > value) { if (value == null) { return; } Dictionary <T, TAdaptee> removedOnChange = null; foreach (var update in value.Operations()) { switch (update.Type) { case CollectionOperationType.Add: _state.OnAdd(update.Item, _func, removedOnChange); break; case CollectionOperationType.Remove: _state.OnRemove(update.Item, ref removedOnChange); break; case CollectionOperationType.Clear: _state.Clear(); break; default: throw new ArgumentOutOfRangeException(); } } var adapter = new Change(value, _state, removedOnChange); var result = new ChangedCollectionData <TAdaptee>(adapter, _state); this.Adaptee.OnNext(result); }
public IEnumerable <CollectionOperation <TAdaptee> > Operations() { foreach (var u in _adaptee.Operations()) { switch (u.Type) { case CollectionOperationType.Add: yield return(CollectionOperation <TAdaptee> .OnAdd(_selector(u.Item))); break; case CollectionOperationType.Remove: yield return(CollectionOperation <TAdaptee> .OnRemove(_selector(u.Item))); break; case CollectionOperationType.Clear: yield return(CollectionOperation <TAdaptee> .OnClear()); break; default: throw new ArgumentOutOfRangeException(); } } }
public IEnumerable <CollectionOperation <T> > Operations() { foreach (var update in _adaptee.Operations()) { if (update.Type == CollectionOperationType.Clear) { yield return(update); } else if (_criterion.Invoke(update.Item)) { yield return(update); } } }
protected override IEnumerable <ListOperation <TAdaptee> > Enumerate() { foreach (var update in _adaptee.Operations()) { switch (update.Type) { case ListOperationType.Add: yield return(ListOperation <TAdaptee> .OnAdd( _state.Get(update.Item, _removed), update.Index)); break; case ListOperationType.Remove: yield return(ListOperation <TAdaptee> .OnRemove( _state.Get(update.Item, _removed), update.Index)); break; case ListOperationType.Move: yield return(ListOperation <TAdaptee> .OnMove( _state.Get(update.Item, _removed), update.Index, update.OriginalIndex)); break; case ListOperationType.Replace: yield return(ListOperation <TAdaptee> .OnReplace( _state.Get(update.Item, _removed), _state.Get(update.ChangedItem, _removed), update.Index)); break; case ListOperationType.Clear: yield return(ListOperation <TAdaptee> .OnClear()); break; default: throw new ArgumentOutOfRangeException(); } } }
private static IChange <ListOperation <TAdaptee> > Apply <T, TAdaptee>( [NotNull] this SelectState <T, TAdaptee> state, [NotNull] IChange <ListOperation <T> > value, [NotNull] Func <T, TAdaptee> func) { Dictionary <T, TAdaptee> removedOnChange = null; foreach (var update in value.Operations()) { switch (update.Type) { case ListOperationType.Add: state.OnAdd(update.Item, func, removedOnChange); break; case ListOperationType.Remove: state.OnRemove(update.Item, ref removedOnChange); break; case ListOperationType.Move: break; case ListOperationType.Replace: state.OnRemove(update.Item, ref removedOnChange); state.OnAdd(update.Item, func, removedOnChange); break; case ListOperationType.Clear: state.Clear(); break; default: throw new ArgumentOutOfRangeException(); } } var adapter = new ListChange <T, TAdaptee>(value, state, removedOnChange); return(adapter); }
public IEnumerable <CollectionOperation <T> > Operations() { foreach (var operation in _adaptee.Operations()) { var sum = operation.Match( OnInsert, OnRemove, OnReplace, OnReset ); if (sum.Items != null) { foreach (var item in sum.Items) { yield return(item); } } else { yield return(sum.Item); } } }
public IEnumerable <CollectionOperation <T> > Operations() { foreach (var update in _adaptee.Operations()) { switch (update.Type) { case ListOperationType.Add: yield return(CollectionOperation <T> .OnAdd(update.Item)); break; case ListOperationType.Remove: yield return(CollectionOperation <T> .OnRemove(update.Item)); break; case ListOperationType.Move: break; case ListOperationType.Replace: yield return(CollectionOperation <T> .OnRemove(update.ChangedItem)); yield return(CollectionOperation <T> .OnAdd(update.Item)); break; case ListOperationType.Clear: yield return(CollectionOperation <T> .OnClear()); break; default: throw new ArgumentOutOfRangeException(); } } }