System.Collections.Generic.ReadOnlyCollection.cs file added.
authorCarlos Alberto Cortez <calberto.cortez@gmail.com>
Wed, 8 Sep 2004 08:02:44 +0000 (08:02 -0000)
committerCarlos Alberto Cortez <calberto.cortez@gmail.com>
Wed, 8 Sep 2004 08:02:44 +0000 (08:02 -0000)
svn path=/trunk/mcs/; revision=33560

mcs/class/corlib/System.Collections.Generic/ChangeLog
mcs/class/corlib/System.Collections.Generic/Collection.cs
mcs/class/corlib/System.Collections.Generic/ReadOnlyCollection.cs [new file with mode: 0644]

index d115f59ea1402764cfc4ec313dd3ed6f3888398e..5204794b4824caf3f6737ec7f17026f508e8468b 100644 (file)
@@ -1,3 +1,8 @@
+2004-09-07  Carlos Alberto Cortez <carlos@unixmexico.org>
+
+       * ReadOnlyCollection.cs: New file and changes to 
+       Collection.cs tu support it.
+
 2004-09-05  Marek Safar <marek.safar@seznam.cz>
 
        * Dictionary.cs: Added new file (no implementation).
index c8787ce2d9758a4246e8f38fadb0841c249d2af1..b8b43d977609128af27801c5afebb8766e03f6d0 100644 (file)
@@ -56,15 +56,18 @@ namespace System.Collections.Generic
                        contents = new T [defaultLength];\r
                }\r
 \r
-               public Collection (List <T> list)\r
+               public Collection (List <T> list) : this (list, list.Count * 2)\r
+               {\r
+               }\r
+\r
+               internal Collection (IList <T> list, int length)\r
                {\r
                        if (list == null)\r
                                throw new ArgumentNullException ("list");\r
 \r
-                       contents = new T [list.Count * 2];\r
+                       contents = new T [length];\r
                        list.CopyTo (contents, 0);\r
                        count = list.Count;\r
-\r
                }\r
                \r
                public void Add (T item)\r
@@ -283,7 +286,7 @@ namespace System.Collections.Generic
                // We could try to make List.contents internal,\r
                // avoiding the box and unbox when copying\r
                //\r
-               protected List <T> Items {\r
+               protected internal List <T> Items {\r
 \r
                        get {\r
                                return new List <T> (this);\r
diff --git a/mcs/class/corlib/System.Collections.Generic/ReadOnlyCollection.cs b/mcs/class/corlib/System.Collections.Generic/ReadOnlyCollection.cs
new file mode 100644 (file)
index 0000000..41be464
--- /dev/null
@@ -0,0 +1,227 @@
+//\r
+// System.Collections.Generic.ReadOnlyCollection\r
+//\r
+// Author:\r
+//    Carlos Alberto Cortez (carlos@unixmexico.org)\r
+//\r
+// (C) 2004 Carlos Alberto Cortez\r
+//\r
+\r
+//\r
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)\r
+//\r
+// Permission is hereby granted, free of charge, to any person obtaining\r
+// a copy of this software and associated documentation files (the\r
+// "Software"), to deal in the Software without restriction, including\r
+// without limitation the rights to use, copy, modify, merge, publish,\r
+// distribute, sublicense, and/or sell copies of the Software, and to\r
+// permit persons to whom the Software is furnished to do so, subject to\r
+// the following conditions:\r
+//\r
+// The above copyright notice and this permission notice shall be\r
+// included in all copies or substantial portions of the Software.\r
+//\r
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+//\r
+\r
+#if NET_2_0\r
+using System;\r
+using System.Collections;\r
+using System.Runtime.InteropServices;\r
+\r
+namespace System.Collections.Generic\r
+{\r
+       [CLSCompliant (false)]\r
+       [ComVisible (false)]\r
+       public class ReadOnlyCollection <T> : ICollection<T>, IEnumerable<T>, IList<T>,\r
+               ICollection, IEnumerable, IList\r
+       {\r
+\r
+               Collection<T> collection;\r
+\r
+               public ReadOnlyCollection(IList <T> list)\r
+               {\r
+                       collection = new Collection<T> (list, list.Count);\r
+               }\r
+\r
+               public bool Contains (T value)\r
+               {\r
+                       return collection.Contains (value);\r
+               }\r
+\r
+               public void CopyTo (T[] array, int index)\r
+               {\r
+                       collection.CopyTo (array, index);\r
+               }\r
+\r
+               public IEnumerator<T> GetEnumerator()\r
+               {\r
+                       return collection.GetEnumerator ();\r
+               }\r
+\r
+               void ICollection.CopyTo (Array array, int index)\r
+               {\r
+                       ((IList) collection).CopyTo (array, index);\r
+               }\r
+\r
+               void ICollection<T>.Add (T item)\r
+               {\r
+                       throw new NotSupportedException ();\r
+               }\r
+\r
+               void ICollection<T>.Clear ()\r
+               {\r
+                       throw new NotSupportedException ();\r
+               }\r
+\r
+               bool ICollection<T>.Remove (T item)\r
+               {\r
+                       throw new NotSupportedException ();\r
+               }\r
+\r
+               IEnumerator IEnumerable.GetEnumerator ()\r
+               {\r
+                       return ((IEnumerable) collection).GetEnumerator ();\r
+               }\r
+\r
+               int IList.Add (object value)\r
+               {\r
+                       throw new NotSupportedException ();\r
+               }\r
+\r
+               void IList.Clear()\r
+               {\r
+                       throw new NotSupportedException ();\r
+               }\r
+\r
+               bool IList.Contains (object value)\r
+               {\r
+                       return ((IList) collection).Contains (value);\r
+               }\r
+\r
+               int IList.IndexOf (object value)\r
+               {\r
+                       return ((IList) collection).IndexOf (value);\r
+               }\r
+\r
+               void IList.Insert (int index, object value)\r
+               {\r
+                       throw new NotSupportedException ();\r
+               }\r
+\r
+               void IList.Remove (object value)\r
+               {\r
+                       throw new NotSupportedException ();\r
+               }\r
+\r
+               void IList.RemoveAt(int index)\r
+               {\r
+                       throw new NotSupportedException ();\r
+               }\r
+\r
+               void IList<T>.Insert (int index, T item)\r
+               {\r
+                       throw new NotSupportedException ();\r
+               }\r
+\r
+               void IList<T>.RemoveAt (int index)\r
+               {\r
+                       throw new NotSupportedException ();\r
+               }\r
+\r
+               public int IndexOf (T value)\r
+               {\r
+                       return collection.IndexOf (value);\r
+               }\r
+\r
+               public int Count {\r
+                       \r
+                       get {\r
+                               return collection.Count;\r
+                       }\r
+\r
+               }\r
+\r
+               bool ICollection.IsSynchronized {\r
+                       \r
+                       get {\r
+                               return false;\r
+                       }\r
+                       \r
+               }\r
+\r
+               object ICollection.SyncRoot {\r
+                       \r
+                       get {\r
+                               return ((IList) collection).SyncRoot;\r
+                       }\r
+                       \r
+               }\r
+\r
+               bool ICollection<T>.IsReadOnly {\r
+                       \r
+                       get {\r
+                               return true;\r
+                       }\r
+\r
+               }\r
+\r
+               bool IList.IsReadOnly {\r
+                       \r
+                       get {\r
+                               return true;\r
+                       }\r
+\r
+               }\r
+\r
+               bool IList.IsFixedSize {\r
+                       \r
+                       get {\r
+                               return true;\r
+                       }\r
+                       \r
+               }\r
+\r
+               object IList.this [int index] {\r
+                       \r
+                       get {\r
+                               return ((IList) collection) [index];\r
+                       }\r
+\r
+                       set\r
+                       {\r
+                               throw new NotSupportedException ();\r
+                       }\r
+\r
+               }\r
+\r
+               public T this [int index] {\r
+                       \r
+                       get {\r
+                               return collection [index];\r
+                       }\r
+\r
+                       set {\r
+                               throw new NotSupportedException ();\r
+                       }\r
+               }\r
+\r
+               protected IList<T> Items {\r
+                       \r
+                       get {\r
+                               return collection.Items;\r
+                       }\r
+                       \r
+               }\r
+\r
+       }\r
+}\r
+\r
+#endif\r
+\r