Merge pull request #644 from knocte/connstrings
[mono.git] / mcs / class / System.Configuration / System.Configuration / CommaDelimitedStringCollection.cs
index 181da75bd6848b0c3981e52fa0ea52c76c18f2e8..4913c8098311d7a15561e13f973e4bea66d60cbd 100644 (file)
@@ -26,7 +26,6 @@
 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
 //
 
-#if NET_2_0
 using System;
 using System.Collections.Specialized;
 
@@ -39,58 +38,54 @@ namespace System.Configuration {
 
                bool modified;
                bool readOnly;
+               int originalStringHash = 0;
 
                public bool IsModified {
-                       get {
-                               return modified;
+                       get { 
+                               if (modified)
+                                       return true;
+
+                               string str = ToString ();
+                               if (str == null)
+                                       return false;
+
+                               return str.GetHashCode () != originalStringHash;
                        }
                }
 
                public new bool IsReadOnly {
-                       get {
-                               return readOnly;
-                       }
+                       get { return readOnly; }
                }
 
-               [MonoTODO ("exception type")]
                public new string this [int index] {
-                       get {
-                               return base [index];
-                       }
+                       get { return base [index]; }
                        set {
-                               if (readOnly)
-                                       throw new NotSupportedException (); /* XXX */
+                               if (readOnly) throw new ConfigurationErrorsException ("The configuration is read only");
 
                                base [index] = value;
                                modified = true;
                        }
                }
 
-               [MonoTODO ("exception type")]
                public new void Add (string value)
                {
-                       if (readOnly)
-                               throw new NotSupportedException (); /* XXX */
+                       if (readOnly) throw new ConfigurationErrorsException ("The configuration is read only");
 
                        base.Add (value);
                        modified = true;
                }
 
-               [MonoTODO ("exception type")]
                public new void AddRange (string[] range)
                {
-                       if (readOnly)
-                               throw new NotSupportedException (); /* XXX */
+                       if (readOnly) throw new ConfigurationErrorsException ("The configuration is read only");
 
                        base.AddRange (range);
                        modified = true;
                }
 
-               [MonoTODO ("exception type")]
                public new void Clear ()
                {
-                       if (readOnly)
-                               throw new NotSupportedException (); /* XXX */
+                       if (readOnly) throw new ConfigurationErrorsException ("The configuration is read only");
 
                        base.Clear ();
                        modified = true;
@@ -103,25 +98,22 @@ namespace System.Configuration {
                        CopyTo (contents, 0);
                        
                        col.AddRange (contents);
+                       col.originalStringHash = originalStringHash;
 
                        return col;
                }
 
-               [MonoTODO ("exception type")]
                public new void Insert (int index, string value)
                {
-                       if (readOnly)
-                               throw new NotSupportedException (); /* XXX */
+                       if (readOnly) throw new ConfigurationErrorsException ("The configuration is read only");
 
                        base.Insert (index, value);
                        modified = true;
                }
 
-               [MonoTODO ("exception type")]
                public new void Remove (string value)
                {
-                       if (readOnly)
-                               throw new NotSupportedException (); /* XXX */
+                       if (readOnly) throw new ConfigurationErrorsException ("The configuration is read only");
 
                        base.Remove (value);
                        modified = true;
@@ -132,16 +124,26 @@ namespace System.Configuration {
                        readOnly = true;
                }
 
-               public new string ToString ()
+               public override string ToString ()
                {
+                       if (this.Count == 0)
+                               return null;
+
                        string[] contents = new string[this.Count];
 
                        CopyTo (contents, 0);
 
                        return String.Join (",", contents);
                }
+
+               internal void UpdateStringHash ()
+               {
+                       string str = ToString ();
+                       if (str == null)
+                               originalStringHash = 0;
+                       else
+                               originalStringHash = str.GetHashCode ();
+               }
        }
 
 }
-
-#endif