1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
public class BeforeRemoveEventArgs : EventArgs
{
public BeforeRemoveEventArgs(object item)
{
this.item = item;
}
public object item;
}
public class ListTrigerred<T> : List<T>
{
public delegate void BeforeRemoveEventHandler(object sender, BeforeRemoveEventArgs e);
public event BeforeRemoveEventHandler BeforeRemove;
public new bool Remove(T item)
{
if (BeforeRemove != null)
{
List<T> l = new List<T>();
l.Add(item);
BeforeRemove(this, new BeforeRemoveEventArgs(l));
}
return base.Remove(item);
}
public new int RemoveAll(Predicate<T> match)
{
if (BeforeRemove != null)
BeforeRemove(this, new BeforeRemoveEventArgs(this.FindAll(match)));
return base.RemoveAll(match);
}
public new void RemoveAt(int index)
{
if (BeforeRemove != null)
{
List<T> l = new List<T>();
l.Add(this[index]);
BeforeRemove(this, new BeforeRemoveEventArgs(l));
}
base.RemoveAt(index);
}
public new void RemoveRange(int index, int count)
{
if (BeforeRemove != null)
BeforeRemove(this, new BeforeRemoveEventArgs(this.GetRange(index, count)));
base.RemoveRange(index, count);
}
} |
Partager