2005-12-07 Sebastien Pouliot <sebastien@ximian.com>
[mono.git] / mcs / class / corlib / System.Collections / SortedList.cs
index e1f9320ac4b35fe2ef1c829bbc860015d8d679df..3fc8fe47b684ce83fab7dac9c55c78d3a8291fe9 100644 (file)
@@ -8,7 +8,7 @@
 // 
 
 //
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.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.
 //
 
-
-using System;
-using System.Collections;
 using System.Globalization;
+using System.Runtime.InteropServices;
 
 namespace System.Collections {
 
@@ -43,7 +41,9 @@ namespace System.Collections {
        ///  and by index.
        /// </summary>
        [Serializable]
-       [MonoTODO ("Fix serialization compatibility with MS.NET")]
+#if NET_2_0
+       [ComVisible(true)]
+#endif
        public class SortedList : IDictionary, ICollection,
                                  IEnumerable, ICloneable {
 
@@ -102,6 +102,8 @@ namespace System.Collections {
                {
                }
 
+               // LAMESPEC: MSDN docs talk about an InvalidCastException but 
+               // I wasn't able to duplicate such a case in the unit tests.
                public SortedList (IDictionary d, IComparer comparer)
                {
                        if (d  ==  null)
@@ -112,11 +114,7 @@ namespace System.Collections {
 
                        IDictionaryEnumerator it = d.GetEnumerator ();
                        while (it.MoveNext ()) {
-                               if (it.Key is IComparable) {
-                                       Add (it.Key, it.Value);
-                               } else {
-                                       throw new InvalidCastException("!IComparable");
-                               }
+                               Add (it.Key, it.Value);
                        }
                }
 
@@ -518,8 +516,10 @@ namespace System.Collections {
                        }
 
                        if (freeIndx >= 0) {
-                               if (!overwrite)
-                                       throw new ArgumentException("element already exists");
+                               if (!overwrite) {
+                                       string msg = Locale.GetText ("Key '{0}' already exists in list.", key);
+                                       throw new ArgumentException (msg);
+                               }
 
                                table [freeIndx].value = value;
                                ++modificationCount;
@@ -554,11 +554,6 @@ namespace System.Collections {
                                return null;
                }
 
-               private void InitTable (int capacity)
-               {
-                       InitTable (capacity, false);
-               }
-
                private void InitTable (int capacity, bool forceSize) 
                {
                        if (!forceSize && (capacity < defaultCapacity))