public override ListViewItem Add(ListViewItem value) { if (!noEvents) { AddingItem?.Invoke(this, value); } var o = base.Add(value); if (!noEvents) { AddedItem?.Invoke(this, value); } return(o); }
/// <inheritdoc /> /// <summary> /// Adds an item to the <see cref="T:System.Collections.Generic.ICollection`1"></see>. /// </summary> /// <param name="item">The object to add to the <see cref="T:System.Collections.Generic.ICollection`1"></see>.</param> public void Add(T item) { AddingItemEventArgs <T> addingItemEventArgs = new AddingItemEventArgs <T>(item); AddingItem?.Invoke(this, addingItemEventArgs); if (addingItemEventArgs.Cancel) { return; } _items.Add(item); AddedItemEventArgs <T> addedItemEventArgs = new AddedItemEventArgs <T>(addingItemEventArgs.Item); AddedItem?.Invoke(this, addedItemEventArgs); }
/// <summary> /// Constructs a <see cref="IBidirectionalList{T}"/> given <paramref name="values"/>. /// </summary> /// <param name="values"></param> /// <param name="onAdded"></param> /// <param name="onRemoved"></param> /// <param name="onAdding"></param> /// <param name="onRemoving"></param> public BidirectionalList(IList <T> values , BidirectionalListItemCallback <T> onAdded , BidirectionalListItemCallback <T> onRemoved , BidirectionalListItemCallback <T> onAdding = null , BidirectionalListItemCallback <T> onRemoving = null) { var defaultItemCallback = DefaultItemCallback; // Connect the Bidirectional Item callback conditionally when there is a Callback. void ConnectBidiCallback(BidirectionalListItemCallback <T> callback , Action <BidirectionalList <T>, BidirectionalListItemCallback <T> > onConnect) { if (callback != null) { onConnect.Invoke(this, callback); } } ConnectBidiCallback(onAdded, (x, callback) => x.AddedItem += callback); ConnectBidiCallback(onAdding, (x, callback) => x.AddingItem += callback); ConnectBidiCallback(onRemoved, (x, callback) => x.RemovedItem += callback); ConnectBidiCallback(onRemoving, (x, callback) => x.RemovingItem += callback); // Effectively we are also Adding the items to the initial Collection instance. foreach (var x in values) { AddingItem?.Invoke(x); } Collection = values; foreach (var x in values) { AddedItem?.Invoke(x); } }
/// <summary> /// Constructs a <see cref="IBidirectionalList{T}"/> given <paramref name="values"/>. /// </summary> /// <param name="values"></param> /// <param name="onAdded"></param> /// <param name="onRemoved"></param> /// <param name="onAdding"></param> /// <param name="onRemoving"></param> public BidirectionalList(IList <T> values , BidirectionalListItemCallback <T> onAdded = null , BidirectionalListItemCallback <T> onRemoved = null , BidirectionalListItemCallback <T> onAdding = null , BidirectionalListItemCallback <T> onRemoving = null) { AddedItem += onAdded ?? DefaultCallback(); AddingItem += onAdding ?? DefaultCallback(); RemovedItem += onRemoved ?? DefaultCallback(); RemovingItem += onRemoving ?? DefaultCallback(); // Effectively we are also Adding the items to the initial Collection instance. foreach (var x in values) { AddingItem?.Invoke(x); } _collection = values; foreach (var x in values) { AddedItem?.Invoke(x); } }
private void OnItemAdded(ScriptableItem item) => AddedItem?.Invoke(item);
public void Add(T item) { internalList.Add(item); AddedItem.Invoke(item); }
/// <inheritdoc /> public void Insert(int index, T item) { AddingItem?.Invoke(item); ListAction(x => x.Insert(index, item)); AddedItem?.Invoke(item); }
/// <inheritdoc /> public void Add(T item) { AddingItem?.Invoke(item); ListAction(x => x.Add(item)); AddedItem?.Invoke(item); }
protected void ProcessItemAdded(IntelItem intelItem) { IntelItems.Enqueue(intelItem); AddedItem?.Invoke(this, intelItem); }