2 // System.Collections.CollectionBase.cs
\r
5 // Nick Drochak II (ndrochak@gol.com)
\r
7 // (C) 2001 Nick Drochak II
\r
12 namespace System.Collections {
\r
15 public abstract class CollectionBase : IList, ICollection, IEnumerable {
\r
17 // private instance properties
\r
18 private ArrayList myList;
\r
20 // public instance properties
\r
21 public int Count { get { return InnerList.Count; } }
\r
23 // Public Instance Methods
\r
24 public IEnumerator GetEnumerator() { return InnerList.GetEnumerator(); }
\r
25 public void Clear() {
\r
30 public void RemoveAt (int index) {
\r
31 object objectToRemove;
\r
32 objectToRemove = InnerList[index];
\r
33 OnValidate(objectToRemove);
\r
34 OnRemove(index, objectToRemove);
\r
35 InnerList.RemoveAt(index);
\r
36 OnRemoveComplete(index, objectToRemove);
\r
39 // Protected Instance Constructors
\r
40 protected CollectionBase() {
\r
41 this.myList = new ArrayList();
\r
44 // Protected Instance Properties
\r
45 protected ArrayList InnerList {get { return this.myList; } }
\r
46 protected IList List {get { return this; } }
\r
48 // Protected Instance Methods
\r
49 protected virtual void OnClear() { }
\r
50 protected virtual void OnClearComplete() { }
\r
52 protected virtual void OnInsert(int index, object value) { }
\r
53 protected virtual void OnInsertComplete(int index, object value) { }
\r
55 protected virtual void OnRemove(int index, object value) { }
\r
56 protected virtual void OnRemoveComplete(int index, object value) { }
\r
58 protected virtual void OnSet(int index, object oldValue, object newValue) { }
\r
59 protected virtual void OnSetComplete(int index, object oldValue, object newValue) { }
\r
61 protected virtual void OnValidate(object value) {
\r
62 if (null == value) {
\r
63 throw new System.ArgumentNullException("CollectionBase.OnValidate: Invalid parameter value passed to method: null");
\r
67 // ICollection methods
\r
68 void ICollection.CopyTo(Array array, int index) {
\r
69 InnerList.CopyTo(array, index);
\r
71 object ICollection.SyncRoot {
\r
72 get { return InnerList.SyncRoot; }
\r
74 bool ICollection.IsSynchronized {
\r
75 get { return InnerList.IsSynchronized; }
\r
79 int IList.Add (object value) {
\r
82 newPosition = InnerList.Count;
\r
83 OnInsert(newPosition, value);
\r
84 InnerList.Add(value);
\r
85 OnInsertComplete(newPosition, value);
\r
89 bool IList.Contains (object value) {
\r
90 return InnerList.Contains(value);
\r
93 int IList.IndexOf (object value) {
\r
94 return InnerList.IndexOf(value);
\r
97 void IList.Insert (int index, object value) {
\r
99 OnInsert(index, value);
\r
100 InnerList.Insert(index, value);
\r
101 OnInsertComplete(index, value);
\r
104 void IList.Remove (object value) {
\r
107 removeIndex = InnerList.IndexOf(value);
\r
108 OnRemove(removeIndex, value);
\r
109 InnerList.Remove(value);
\r
110 OnRemoveComplete(removeIndex, value);
\r
113 // IList properties
\r
114 bool IList.IsFixedSize {
\r
115 get { return InnerList.IsFixedSize; }
\r
118 bool IList.IsReadOnly {
\r
119 get { return InnerList.IsReadOnly; }
\r
122 object IList.this[int index] {
\r
123 get { return InnerList[index]; }
\r
126 // make sure we have been given a valid value
\r
128 // save a reference to the object that is in the list now
\r
129 oldValue = InnerList[index];
\r
131 OnSet(index, oldValue, value);
\r
132 InnerList[index] = value;
\r
133 OnSetComplete(index, oldValue, value);
\r