Merge pull request #1135 from kitsilanosoftware/rpm-spec-dead-entries
[mono.git] / mcs / class / corlib / System.Collections.ObjectModel / ReadOnlyCollection.cs
index 2c5866306e425a73848a8f0a238f4ebb83c4b528..7b0510ec9954fb937d1cf1a08351f2befddf3cce 100644 (file)
@@ -2,14 +2,19 @@
 //
 // System.Collections.ObjectModel.ReadOnlyCollection
 //
-// Author:
+// Authors:
 //    Zoltan Varga (vargaz@gmail.com)
+//    David Waite (mass@akuma.org)
+//    Marek Safar (marek.safar@gmail.com)
 //
 // (C) 2005 Novell, Inc.
+// (C) 2005 David Waite
 //
 
 //
 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2005 David Waite
+// Copyright (C) 2011 Xamarin, Inc (http://www.xamarin.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-#if NET_2_0
 using System;
 using System.Collections.Generic;
 using System.Runtime.InteropServices;
+using System.Diagnostics;
 
 namespace System.Collections.ObjectModel
 {
-       [ComVisible(false)]
+       [ComVisible (false)]
        [Serializable]
-       public class ReadOnlyCollection<T> : IList<T>, ICollection<T>, IEnumerable<T>, IList, ICollection, IEnumerable
+       [DebuggerDisplay ("Count={Count}")]
+       [DebuggerTypeProxy (typeof (CollectionDebuggerView<>))]
+       public class ReadOnlyCollection<T> : IList<T>, IList
+#if NET_4_5
+               , IReadOnlyList<T>
+#endif
        {
-               public ReadOnlyCollection (IList<T> list)
+               IList <T> list;
+               
+               public ReadOnlyCollection (IList <T> list)
                {
-                       throw new NotImplementedException ();
+                       if (list == null)
+                               throw new ArgumentNullException ("list");
+                       this.list = list;
                }
 
-               public void Add (T item)
+               void ICollection<T>.Add (T item)
                {
-                       throw new NotImplementedException ();
+                       throw new NotSupportedException ();
                }
-
-               public void Clear ()
+               
+               void ICollection<T>.Clear ()
                {
-                       throw new NotImplementedException ();
+                       throw new NotSupportedException ();
                }
 
-               public bool Contains (T item)
+               public bool Contains (T value)
                {
-                       throw new NotImplementedException ();
+                       return list.Contains (value);
                }
 
-               public void CopyTo (T[] array, int index)
+               public void CopyTo (T [] array, int index)
                {
-                       throw new NotImplementedException ();
+                       list.CopyTo (array, index);
                }
 
-               public IEnumerator<T> GetEnumerator ()
+               public IEnumerator <T> GetEnumerator ()
                {
-                       throw new NotImplementedException ();
+                       return list.GetEnumerator ();
                }
 
-               public int IndexOf (T item)
+               public int IndexOf (T value)
                {
-                       throw new NotImplementedException ();
+                       return list.IndexOf (value);
                }
 
-               public void Insert (int index, T item)
+               void IList<T>.Insert (int index, T item)
                {
-                       throw new NotImplementedException ();
+                       throw new NotSupportedException ();
                }
 
-               public bool Remove (T item)
+               bool ICollection<T>.Remove (T item)
                {
-                       throw new NotImplementedException ();
+                       throw new NotSupportedException ();
                }
 
-               public void RemoveAt (int index)
+               void IList<T>.RemoveAt (int index)
                {
-                       throw new NotImplementedException ();
+                       throw new NotSupportedException ();
                }
 
-               public virtual int Count {
-                       get {
-                               throw new NotImplementedException ();
-                       }
+               public int Count {
+                       get { return list.Count; }
                }
 
-               public virtual T this [int index] {
-                       get {
-                               throw new NotImplementedException ();
-                       }
-                       set {
-                               throw new NotImplementedException ();
-                       }
+               protected IList<T> Items {
+                       get { return list; }
                }
 
-               public bool IsReadOnly {
-                       get {
-                               throw new NotImplementedException ();
-                       }
+               public T this [int index] {
+                       get { return list [index]; }
+               }
+
+               T IList<T>.this [int index] {
+                       get { return this [index]; }
+                       set { throw new NotSupportedException (); }
+               }
+
+               bool ICollection<T>.IsReadOnly {
+                       get { return true; }
                }
 
 #region Not generic interface implementations
-               void ICollection.CopyTo (Array array, int arrayIndex)
+               void ICollection.CopyTo (Array array, int index)
                {
-                       throw new NotImplementedException ();
+                       ((ICollection)list).CopyTo (array, index);
                }
-               
-               IEnumerator IEnumerable.GetEnumerator()
+                               
+               IEnumerator IEnumerable.GetEnumerator ()
                {
-                       throw new NotImplementedException ();
+                       return ((IEnumerable) list).GetEnumerator ();
                }
                
-               int IList.Add (object item)
+               int IList.Add (object value)
                {
-                       throw new NotImplementedException ();
+                       throw new NotSupportedException ();
                }
                
-               bool IList.Contains (object item)
+               void IList.Clear ()
                {
-                       throw new NotImplementedException ();
+                       throw new NotSupportedException ();
+               }
+
+               bool IList.Contains (object value)
+               {
+                       if (CollectionHelpers.IsValidItem<T> (value))
+                               return list.Contains ((T) value);
+                       return false;
                }
                
-               int IList.IndexOf (object item)
+               int IList.IndexOf (object value)
                {
-                       throw new NotImplementedException ();
+                       if (CollectionHelpers.IsValidItem<T> (value))
+                               return list.IndexOf ((T) value);
+                       return -1;
                }
                
-               void IList.Insert (int index, object item)
+               void IList.Insert (int index, object value)
                {
-                       throw new NotImplementedException ();
+                       throw new NotSupportedException ();
                }
                
-               void IList.Remove (object item)
+               void IList.Remove (object value)
                {
-                       throw new NotImplementedException ();
+                       throw new NotSupportedException ();
                }
                
+               void IList.RemoveAt (int index)
+               {
+                       throw new NotSupportedException ();
+               }
+
                bool ICollection.IsSynchronized {
-                       get {
-                               throw new NotImplementedException ();
-                       }
+                       get { return false; }
                }
                
                object ICollection.SyncRoot {
-                       get {
-                               throw new NotImplementedException ();
-                       }
+                       get { return this; }
                }
+
                bool IList.IsFixedSize {
-                       get {
-                               throw new NotImplementedException ();
-                       }
+                       get { return true; }
                }
                
                bool IList.IsReadOnly {
-                       get {
-                               throw new NotImplementedException ();
-                       }
+                       get { return true; }
                }
                
                object IList.this [int index] {
-                       get {
-                               throw new NotImplementedException ();
-                       }
-                       set {
-                               throw new NotImplementedException ();
-                       }
+                       get { return list [index]; }
+                       set { throw new NotSupportedException (); }
                }
 #endregion
        }
 }
-#endif