1 // Licensed to the .NET Foundation under one or more agreements. 2 // The .NET Foundation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 /*============================================================================= 6 ** 7 ** Class: ReadOnlyCollectionBase 8 ** 9 ** Purpose: Provides the abstract base class for a 10 ** strongly typed non-generic read-only collection. 11 ** 12 =============================================================================*/ 13 14 15 namespace System.Collections 16 { 17 // Useful base class for typed readonly collections where items derive from object 18 [Serializable] 19 public abstract class ReadOnlyCollectionBase : ICollection 20 { 21 private ArrayList _list; 22 23 protected ArrayList InnerList 24 { 25 get 26 { 27 if (_list == null) 28 _list = new ArrayList(); 29 return _list; 30 } 31 } 32 33 public virtual int Count 34 { 35 get { return InnerList.Count; } 36 } 37 38 bool ICollection.IsSynchronized 39 { 40 get { return InnerList.IsSynchronized; } 41 } 42 43 object ICollection.SyncRoot 44 { 45 get { return InnerList.SyncRoot; } 46 } 47 ICollection.CopyTo(Array array, int index)48 void ICollection.CopyTo(Array array, int index) 49 { 50 InnerList.CopyTo(array, index); 51 } 52 GetEnumerator()53 public virtual IEnumerator GetEnumerator() 54 { 55 return InnerList.GetEnumerator(); 56 } 57 } 58 } 59