2 using System.Collections;
3 using System.Collections.Generic;
5 namespace DirectOutput.General.Generic
11 public class ExtList<T> : IList<T>, ICollection<T>, IEnumerable<T>, IEnumerable, ICollection, IList
13 private List<T> _InternalList =
new List<T>();
21 public int IndexOf(T Item)
24 return _InternalList.IndexOf(Item);
32 public void CopyTo(T[] Array,
int ArrayIndex)
34 _InternalList.CopyTo(Array, ArrayIndex);
43 public bool IsReadOnly
52 public IEnumerator<T> GetEnumerator()
54 return _InternalList.GetEnumerator();
61 IEnumerator IEnumerable.GetEnumerator()
63 return GetEnumerator();
70 public void Add(T NewListItem)
72 if (BeforeInsert != null)
74 BeforeInsert(
this,
new InsertEventArgs<T>(-1, NewListItem));
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)
118 public void Insert(
int Index, T Item)
120 if (BeforeInsert != null)
122 BeforeInsert(
this,
new InsertEventArgs<T>(Index, Item));
125 _InternalList.Insert(Index, Item);
127 if (AfterInsert != null)
129 AfterInsert(
this,
new InsertEventArgs<T>(Index, Item));
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; }
169 public bool Remove(T ItemToRemove)
171 bool ItemRemoved =
false;
172 if (_InternalList.Contains(ItemToRemove))
174 int Index = _InternalList.IndexOf(ItemToRemove);
175 if (BeforeRemove != null)
177 BeforeRemove(
this,
new RemoveEventArgs<T>(Index, ItemToRemove));
180 _InternalList.Remove(ItemToRemove);
182 if (AfterRemove != null)
184 AfterRemove(
this,
new RemoveEventArgs<T>(Index, ItemToRemove));
195 public void RemoveAt(
int Index)
197 T ItemToRemove =
this[Index];
198 if (BeforeRemove != null)
200 BeforeRemove(
this,
new RemoveEventArgs<T>(Index, ItemToRemove));
203 _InternalList.RemoveAt(Index);
205 if (AfterRemove != null)
207 AfterRemove(
this,
new RemoveEventArgs<T>(Index, ItemToRemove));
219 public bool Contains(T ItemToCheck)
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)
241 BeforeSet(
this,
new SetEventArgs<T>(Index, OldItem, value));
244 _InternalList[Index] = value;
245 if (AfterSet != null)
247 AfterSet(
this,
new SetEventArgs<T>(Index, OldItem, value));
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;
368 public ExtList(IEnumerable<T> EnumerableList)
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;
407 public bool Contains(
object value)
409 if (value.GetType() != typeof(T))
411 throw new ArgumentException(
" Value is of a wrong type.");
413 return _InternalList.Contains((T)value);
416 public int IndexOf(
object 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; }
439 public void Remove(
object value)
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;