namespace System { public delegate void Action(); public delegate void Action(T1 arg1, T2 arg2); public delegate void Action(T1 arg1, T2 arg2, T3 arg3); public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4); public delegate TResult Func(); public delegate TResult Func(T1 arg1); public delegate TResult Func(T1 arg1, T2 arg2); public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3); public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4); } namespace System.Collections.Specialized { public interface INotifyCollectionChanged { event NotifyCollectionChangedEventHandler CollectionChanged; } /// /// This enum describes the action that caused a CollectionChanged event. /// public enum NotifyCollectionChangedAction { /// One or more items were added to the collection. Add, /// One or more items were removed from the collection. Remove, /// One or more items were replaced in the collection. Replace, /// One or more items were moved within the collection. Move, /// The contents of the collection changed dramatically. Reset, } /// /// Arguments for the CollectionChanged event. A collection that supports /// INotifyCollectionChangedThis raises this event whenever an item is added or /// removed, or when the contents of the collection changes dramatically. /// public class NotifyCollectionChangedEventArgs : EventArgs { #region .ctors /// /// Construct a NotifyCollectionChangedEventArgs that describes a reset change. /// /// The action that caused the event (must be Reset). public NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction action) : this(action, null, -1) { } /// /// Construct a NotifyCollectionChangedEventArgs that describes a one-item change. /// /// The action that caused the event; can only be Reset, Add or Remove action. /// The item affected by the change. public NotifyCollectionChangedEventArgs( NotifyCollectionChangedAction action, object changedItem) : this(action, changedItem, -1) { } /// /// Construct a NotifyCollectionChangedEventArgs that describes a one-item change. /// /// The action that caused the event. /// The item affected by the change. /// The index where the change occurred. public NotifyCollectionChangedEventArgs( NotifyCollectionChangedAction action, object changedItem, int index) : this(action, changedItem == null? null: new object[]{ changedItem }, index) { } /// /// Construct a NotifyCollectionChangedEventArgs that describes a multi-item change. /// /// The action that caused the event. /// The items affected by the change. public NotifyCollectionChangedEventArgs( NotifyCollectionChangedAction action, IList changedItems) : this(action, changedItems, -1) { } /// /// Construct a NotifyCollectionChangedEventArgs that describes a multi-item change (or a reset). /// /// The action that caused the event. /// The items affected by the change. /// The index where the change occurred. public NotifyCollectionChangedEventArgs( NotifyCollectionChangedAction action, IList changedItems, int startingIndex) { _action = action; if (action == NotifyCollectionChangedAction.Add) { _newItems = changedItems; _newStartingIndex = startingIndex; } else if (action == NotifyCollectionChangedAction.Remove) { _oldItems = changedItems; _oldStartingIndex = startingIndex; } } /// /// Construct a NotifyCollectionChangedEventArgs that describes a one-item Replace event. /// /// Can only be a Replace action. /// The new item replacing the original item. /// The original item that is replaced. public NotifyCollectionChangedEventArgs( NotifyCollectionChangedAction action, object newItem, object oldItem) : this(action, new object[] { newItem }, new object[] { oldItem }, -1) { } /// /// Construct a NotifyCollectionChangedEventArgs that describes a one-item Replace event. /// /// Can only be a Replace action. /// The new item replacing the original item. /// The original item that is replaced. /// The index of the item being replaced. public NotifyCollectionChangedEventArgs( NotifyCollectionChangedAction action, object newItem, object oldItem, int index) : this(action, new object[] { newItem }, new object[] { oldItem }, index) { } /// /// Construct a NotifyCollectionChangedEventArgs that describes a multi-item Replace event. /// /// Can only be a Replace action. /// The new items replacing the original items. /// The original items that are replaced. public NotifyCollectionChangedEventArgs( NotifyCollectionChangedAction action, IList newItems, IList oldItems) : this(action, newItems, oldItems, -1) { } /// /// Construct a NotifyCollectionChangedEventArgs that describes a multi-item Replace event. /// /// Can only be a Replace action. /// The new items replacing the original items. /// The original items that are replaced. /// The starting index of the items being replaced. public NotifyCollectionChangedEventArgs( NotifyCollectionChangedAction action, IList newItems, IList oldItems, int startingIndex) { _action = action; _newItems = newItems; _newStartingIndex = startingIndex; _oldItems = oldItems; _oldStartingIndex = startingIndex; } /// /// Construct a NotifyCollectionChangedEventArgs that describes a one-item Move event. /// /// Can only be a Move action. /// The item affected by the change. /// The new index for the changed item. /// The old index for the changed item. public NotifyCollectionChangedEventArgs( NotifyCollectionChangedAction action, object changedItem, int index, int oldIndex) : this(action, new object[]{changedItem}, index, oldIndex) { } /// /// Construct a NotifyCollectionChangedEventArgs that describes a multi-item Move event. /// /// The action that caused the event. /// The items affected by the change. /// The new index for the changed items. /// The old index for the changed items. public NotifyCollectionChangedEventArgs( NotifyCollectionChangedAction action, IList changedItems, int index, int oldIndex) { _action = action; _newItems = changedItems; _newStartingIndex = index; _oldItems = changedItems; _oldStartingIndex = oldIndex; } #endregion #region Properties private readonly NotifyCollectionChangedAction _action; /// /// The action that caused the event. /// public NotifyCollectionChangedAction Action { get { return _action; } } private readonly IList _newItems; /// /// The items affected by the change. /// public IList NewItems { get { return _newItems; } } private readonly IList _oldItems; /// /// The old items affected by the change (for Replace events). /// public IList OldItems { get { return _oldItems; } } private readonly int _newStartingIndex = -1; /// /// The index where the change occurred. /// public int NewStartingIndex { get { return _newStartingIndex; } } private readonly int _oldStartingIndex = -1; /// /// The old index where the change occurred (for Move events). /// public int OldStartingIndex { get { return _oldStartingIndex; } } #endregion } /// /// The delegate to use for handlers that receive the CollectionChanged event. /// public delegate void NotifyCollectionChangedEventHandler(object sender, NotifyCollectionChangedEventArgs e); }