private void DoUpdate(ISortedChangeSet <TObject, TKey> updates, IObservableCollection <TObject> list) { foreach (var update in updates) { switch (update.Reason) { case ChangeReason.Add: list.Insert(update.CurrentIndex, update.Current); break; case ChangeReason.Remove: list.RemoveAt(update.CurrentIndex); break; case ChangeReason.Moved: list.Move(update.PreviousIndex, update.CurrentIndex); break; case ChangeReason.Update: if (update.PreviousIndex != update.CurrentIndex) { list.RemoveAt(update.PreviousIndex); list.Insert(update.CurrentIndex, update.Current); } else { list.Replace(update.Previous.Value, update.Current); } break; } } }
public void ReplaceWithRange(T from, T to) { var iFrom = _allItems.IndexOf(from); var iTo = _allItems.IndexOf(to); if (iFrom < 0 || iTo < 0) { return; //normally unreachable code } if (iFrom > iTo) { var tmp = iFrom; iFrom = iTo; iTo = tmp; } _selectedItems.Replace( _allItems.Skip(iFrom).Take(iTo - iFrom + 1)); }
public void Replace() { //NB: the following is a replace bcause the hash code of user is calculated from the user name var person = new Person("Adult1", 50); var replaced = new Person("Adult1", 50); _collection.Add(person); _collection.Replace(person, replaced); Assert.AreEqual(2, _results.Messages.Count, "Should be 1 updates"); Assert.AreEqual(1, _results.Data.Count, "Should be 1 item in the cache"); Assert.AreEqual(1, _results.Messages.First().Adds, "First message should be an add"); Assert.AreEqual(1, _results.Messages.Skip(1).First().Updates, "First message should be an update"); }
public MasterDetailsProgram(ISomeService someService) { _fetchData = new RemoteActionsCallerForm(x => { x.Add(someService.FetchHeaders, y => _headerItems.Replace(y)); x.Add(someService.FetchDetails, y => _detailItems.Replace(y)); }); _headers = new HeadersForm(); _details = new DetailsForm(); _headerItems.Changed += (_, __, ___) => { _headers.Headers.Items.Replace(_headerItems); }; _layoutChoice = new EnumChoiceForm <LayoutChoice>( "Choose screen layout", true, LayoutChoice.Horizontal, x => x.ToString(), x => x.Choice.Widget.ClassList.Add("horizontalOrVerticalChoice")); }
public static void Replace <T>(this IObservableCollection <T> self, IEnumerable <T> items) { self.Replace(items.ToArray()); }