3 using System.Collections.Generic;
11 public class ExtList<T> : IList<T>, ICollection<T>, IEnumerable<T>, IEnumerable, ICollection, IList
13 private List<T> _InternalList =
new List<T>();
24 return _InternalList.IndexOf(Item);
32 public void CopyTo(T[] Array,
int ArrayIndex)
34 _InternalList.CopyTo(Array, ArrayIndex);
43 public bool IsReadOnly
54 return _InternalList.GetEnumerator();
61 IEnumerator IEnumerable.GetEnumerator()
63 return GetEnumerator();
70 public void Add(T NewListItem)
72 if (BeforeInsert != null)
76 _InternalList.Add(NewListItem);
77 if (AfterInsert != null)
79 AfterInsert(
this,
new InsertEventArgs<T>(_InternalList.IndexOf(NewListItem), NewListItem));
88 public void AddRange(IEnumerable<T> Collection)
90 foreach (T Item
in Collection)
104 foreach (T Item
in this)
120 if (BeforeInsert != null)
125 _InternalList.Insert(Index, Item);
127 if (AfterInsert != null)
142 if (BeforeClear != null)
144 BeforeClear(
this,
new EventArgs());
146 _InternalList.Clear();
147 if (AfterClear != null)
149 AfterClear(
this,
new EventArgs());
160 get {
return _InternalList.Count; }
171 bool ItemRemoved =
false;
172 if (_InternalList.Contains(ItemToRemove))
174 int Index = _InternalList.IndexOf(ItemToRemove);
175 if (BeforeRemove != null)
180 _InternalList.Remove(ItemToRemove);
182 if (AfterRemove != null)
197 T ItemToRemove =
this[Index];
198 if (BeforeRemove != null)
203 _InternalList.RemoveAt(Index);
205 if (AfterRemove != null)
221 return _InternalList.Contains(ItemToCheck);
232 public T
this[
int Index]
235 get {
return _InternalList[Index]; }
238 T OldItem = _InternalList[Index];
239 if (BeforeSet != null)
244 _InternalList[Index] = value;
245 if (AfterSet != null)
258 _InternalList.Sort();
266 public void Sort(IComparer<T> Comparer)
268 _InternalList.Sort(Comparer);
274 public void Sort(Comparison<T> Comparison)
276 _InternalList.Sort(Comparison);
287 return _InternalList.ToArray();
310 #region Insert Events
327 #region Remove Events
354 public event EventHandler<SetEventArgs<T>>
AfterSet;
370 AddRange(EnumerableList);
375 #region ICollection Member
377 public void CopyTo(Array array,
int index)
379 ((ICollection)_InternalList).CopyTo(array, index);
382 public bool IsSynchronized
384 get {
return ((ICollection)_InternalList).IsSynchronized; }
387 public object SyncRoot
389 get {
return ((ICollection)_InternalList).SyncRoot; }
397 public int Add(
object value)
399 if(value.GetType() != typeof(T)) {
400 throw new ArgumentException(
" Value is of a wrong type.");
403 return _InternalList.Count - 1;
409 if (value.GetType() != typeof(T))
411 throw new ArgumentException(
" Value is of a wrong type.");
413 return _InternalList.Contains((T)value);
418 if (value.GetType() != typeof(T))
420 throw new ArgumentException(
" Value is of a wrong type.");
422 return _InternalList.IndexOf((T)value);
425 public void Insert(
int index,
object value)
427 if (value.GetType() != typeof(T))
429 throw new ArgumentException(
" Value is of a wrong type.");
431 Insert(index, (T)value);
434 public bool IsFixedSize
436 get {
return ((IList)_InternalList).IsFixedSize; }
441 if (value.GetType() != typeof(T))
443 throw new ArgumentException(
" Value is of a wrong type.");
448 object IList.this[
int index]
452 return _InternalList[index];
456 this[index] = (T)value;
T[] ToArray()
Returns a array containg the ExtList items.
Event args for Set events.
int IndexOf(T Item)
Determines the index of a specific item.
bool Contains(T ItemToCheck)
Checks wether the specified item is contained in the ExtList.
void Insert(int index, object value)
void Sort()
Sorts the ExtList.
EventErgs for remove events
ExtList(IEnumerable< T > EnumerableList)
void CopyTo(Array array, int index)
bool Remove(T ItemToRemove)
Romves a item from the ExtList.
EventHandler< SetEventArgs< T > > AfterSet
Fires after a item has been set in the ExtList.
void CopyTo(T[] Array, int ArrayIndex)
Copies the elements of the ExtList to an Array, starting at a particular Array index.
EventHandler< EventArgs > BeforeClear
Fires before the ExtList is cleared. If a exception is trown within the events, the list is not clea...
int IndexOf(object value)
void AddRange(IEnumerable< T > Collection)
Adds a list of items to the ExtList.
void Clear()
Clears the ExtList.
void Sort(IComparer< T > Comparer)
Sorts the ExtList.
void Sort(Comparison< T > Comparison)
Sorts the elements in the entire ExtList using the specified System.Comparison.
EventHandler< InsertEventArgs< T > > BeforeInsert
Fires before a new item is inserted into the ExtList. If a exception is occurs in the event...
void Remove(object value)
bool Contains(object value)
IEnumerator< T > GetEnumerator()
Returns an enumerator that iterates through a ExtList.
ExtList< T > Clone()
Creates a clone of the ExtList
void Insert(int Index, T Item)
Inserts an item to the ExtList at the specified Index.
EventHandler< RemoveEventArgs< T > > AfterRemove
Fires after a item is removed from the ExtList.
Extended version of the generic List class supporting events for various actions on the list...
EventHandler< RemoveEventArgs< T > > BeforeRemove
Fires before a item is removed from the ExtList.
Eventargs of BeforeInsert and AfterInsert events.
EventHandler< SetEventArgs< T > > BeforeSet
Fires before a item is set in the ExtList. OnValidate is called prior to this method.
void Add(T NewListItem)
Adds a new item to the ExtList.
EventHandler< EventArgs > AfterClear
Fires after the ExtList is cleared.
EventHandler< InsertEventArgs< T > > AfterInsert
Fires after a new item is inserted into the ExtList. OnValidate is called prior to this method...
void RemoveAt(int Index)
Removes a item at a specified index.