/// <summary> /// Internal base method to add all elements in collection /// </summary> private void AddElementInternal(T item, T newItem, bool after) { //check elements CheckDuplicationItem(newItem); LinkedListNode <T> oldNode = GetExistEntry(item); //add element after LinkedListNode <T> newNode = new LinkedListNode <T>(newItem); //select to add first/last + add if (after) { _elementsList.AddAfter(oldNode, newNode); } else { _elementsList.AddBefore(oldNode, newNode); } _elementsMap.Add(newItem, newNode); //rise event var args = after ? NotifySetChangedEventArgs <T> .ConstructAddAfterAction(item, newItem) : NotifySetChangedEventArgs <T> .ConstructAddBeforeAction(item, newItem); OnCollectionChanged?.Invoke(args); }
public void Clear() { //clear collections _elementsMap.Clear(); _elementsList.Clear(); //rise clear event OnCollectionChanged?.Invoke(NotifySetChangedEventArgs <T> .ConstructClear()); }
/// <summary> /// Try add first element to collection /// </summary> private bool TryAddFirstInternal(T item) { //check count if (Count != 0) { return(false); } //check null item CheckNullElement(item); //add to collections LinkedListNode <T> newNode = _elementsList.AddFirst(item); _elementsMap.Add(item, newNode); //change event OnCollectionChanged?.Invoke(NotifySetChangedEventArgs <T> .ConstructAddFirst(item)); return(true); }
public bool Remove(T item) { //check element CheckNullElement(item); //check exist LinkedListNode <T> entry; if (!_elementsMap.TryGetValue(item, out entry)) { return(false); } //remove _elementsMap.Remove(item); _elementsList.Remove(entry.Value); //rise change event var args = NotifySetChangedEventArgs <T> .ConstructRemoveAction(item); OnCollectionChanged?.Invoke(args); return(true); }