public void Add(T item) { // Here we can do what ever we want, buffering multiple events etc.. BeforeAdd?.Invoke(this, null); _list.Add(item); AfterAdd?.Invoke(this, null); }
public virtual void AddAt(int index, TKey key, TValue item) { DictionaryBeforeEventArgs <TKey, TValue> e = new DictionaryBeforeEventArgs <TKey, TValue> (key, item); // Raise before events: bool bubble = true; if (BeforeAdd != null) { foreach (DictionaryBeforeDelegate <TKey, TValue> function in BeforeAdd.GetInvocationList()) { e.Bubble = true; function.Invoke(this, e); bubble = bubble && e.Bubble; } } if (!bubble) { return; } // Add item: // Use value returend by event: if (m_bReplaceDuplicateKeys && ContainsKey(TransformKey(e.Key))) //check if it contains and remove { Remove(TransformKey(e.Key)); } base.Add(TransformKey(e.Key), e.Value); if (index != -1) { m_col.Insert(index, e.Key); } else { m_col.Add(e.Key); } // Raise after events: if (AfterAdd != null) { AfterAdd.Invoke(this, e); } }
private IRepository <TEntity> CreateRepository <TEntity>() where TEntity : class { var repoMock = new Mock <IRepository <TEntity> >(MockBehavior.Strict); repoMock.Setup(m => m.All()).Returns(EntityFrameworkUtilities.GetDbSet(Entities.Where(e => e is TEntity).Cast <TEntity>().AsQueryable())); repoMock.Setup(m => m.Add(It.IsAny <TEntity>())) .Callback <TEntity>(e => { BeforeAdd?.Invoke(e); Entities.Add(e); }) .Returns <TEntity>(e => e); repoMock.Setup(m => m.Delete(It.IsAny <TEntity>())).Callback <TEntity>(e => { Entities.Remove(e); }); return(repoMock.Object); }
protected override void OnBeforeAdd(T entity) { BeforeAdd?.Invoke(entity); _validator?.ValidateAndThrowOnCreate(entity); }
/// <summary> /// Raises the <see cref="BeforeAdd"/> event. /// </summary> /// <returns><c>true</c>, if it is OK for the add-item to continue, <c>false</c> if it is has been cancelled.</returns> /// <param name="args">Event arguments.</param> protected bool HandleBeforeAdd(BeforeModifyEventArgs <TItem> args) { BeforeAdd?.Invoke(this, args); return((!(args is ICancelable cancelable)) || !cancelable.IsCancelled); }
protected virtual void OnBeforeAdd(T entity) { BeforeAdd?.Invoke(entity); }