2007-12-18 Carlos Alberto Cortez <calberto.cortez@gmail.com>
[mono.git] / mcs / class / Mono.Data / ProviderCollection.cs
old mode 100755 (executable)
new mode 100644 (file)
index 154b9d7..9541182
@@ -8,6 +8,27 @@
 // Copyright (C) Brian Ritchie, 2002\r
 // \r
 //\r
+\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
 namespace Mono.Data \r
 {\r
        using System;\r
@@ -21,7 +42,7 @@ namespace Mono.Data
        ///    </para>\r
        /// </summary>\r
        /// <seealso cref='.ProviderCollection'/>\r
-       [Serializable()]\r
+       [Serializable ()]\r
        public class ProviderCollection : DictionaryBase  \r
        {\r
                \r
@@ -30,7 +51,8 @@ namespace Mono.Data
                ///       Initializes a new instance of <see cref='.ProviderCollection'/>.\r
                ///    </para>\r
                /// </summary>\r
-               public ProviderCollection() \r
+               public ProviderCollection ()\r
+\r
                {\r
                }\r
                \r
@@ -42,9 +64,12 @@ namespace Mono.Data
                /// <param name='value'>\r
                ///       A <see cref='.ProviderCollection'/> from which the contents are copied\r
                /// </param>\r
-               public ProviderCollection(ProviderCollection value) \r
+               public ProviderCollection (ProviderCollection value) \r
                {\r
-                       this.AddRange(value);\r
+                       if (value == null) \r
+                               throw new System.ArgumentNullException ("value");\r
+\r
+                       this.AddRange (value);\r
                }\r
                \r
                /// <summary>\r
@@ -55,9 +80,12 @@ namespace Mono.Data
                /// <param name='value'>\r
                ///       A array of <see cref='.Provider'/> objects with which to intialize the collection\r
                /// </param>\r
-               public ProviderCollection(Provider[] value) \r
+               public ProviderCollection (Provider[] value) \r
                {\r
-                       this.AddRange(value);\r
+                       if (value == null) \r
+                               throw new System.ArgumentNullException ("value");\r
+\r
+                       this.AddRange (value);\r
                }\r
                \r
                /// <summary>\r
@@ -68,46 +96,50 @@ namespace Mono.Data
                ///    <para> The entry at the specified index of the collection.</para>\r
                /// </value>\r
                /// <exception cref='System.ArgumentOutOfRangeException'><paramref name='index'/> is outside the valid range of indexes for the collection.</exception>\r
-               public Provider this[string Name] \r
+               public Provider this [string Name] \r
                {\r
-                       get \r
-                       {\r
-                               return ((Provider)(Dictionary[Name]));\r
+                       get {                           \r
+                               return ((Provider)(Dictionary [Name]));\r
                        }\r
-                       set \r
-                       {\r
-                               Dictionary[Name] = value;\r
+                       set {\r
+                               Dictionary [Name] = value;\r
                        }\r
                }\r
 \r
                public Provider FindByCommandType(Type CommandType)\r
                {\r
-                       foreach (Provider p in this)\r
-                       {\r
-                               if (p.CommandType==CommandType)\r
+                       if (CommandType == null) \r
+                               throw new System.ArgumentNullException ("CommandType");\r
+\r
+                       foreach (Provider p in this) {\r
+                               if (p.CommandType == CommandType)\r
                                        return p;\r
                        }\r
-                       throw new IndexOutOfRangeException();\r
+                       throw new IndexOutOfRangeException ();\r
                }\r
 \r
                public Provider FindByDataAdapterType(Type DataAdapterType)\r
                {\r
-                       foreach (Provider p in this)\r
-                       {\r
-                               if (p.DataAdapterType==DataAdapterType)\r
+                       if (DataAdapterType == null) \r
+                               throw new System.ArgumentNullException ("DataAdapterType");\r
+\r
+                       foreach (Provider p in this) {\r
+                               if (p.DataAdapterType == DataAdapterType)\r
                                        return p;\r
                        }\r
-                       throw new IndexOutOfRangeException();\r
+                       throw new IndexOutOfRangeException ();\r
                }\r
 \r
                public Provider FindByConnectionType(Type ConnectionType)\r
                {\r
-                       foreach (Provider p in this)\r
-                       {\r
-                               if (p.ConnectionType==ConnectionType)\r
+                       if (ConnectionType == null) \r
+                               throw new System.ArgumentNullException("ConnectionType");\r
+\r
+                       foreach (Provider p in this) {\r
+                               if (p.ConnectionType == ConnectionType)\r
                                        return p;\r
                        }\r
-                       throw new IndexOutOfRangeException();\r
+                       throw new IndexOutOfRangeException ();\r
                }\r
 \r
                /// <summary>\r
@@ -121,7 +153,10 @@ namespace Mono.Data
                /// <seealso cref='.ProviderCollection.AddRange'/>\r
                public void Add(Provider value) \r
                {\r
-                       Dictionary.Add(value.Name, value);\r
+                       if (value == null) \r
+                               throw new System.ArgumentNullException ("value");\r
+\r
+                       Dictionary.Add (value.Name, value);\r
                }\r
                \r
                /// <summary>\r
@@ -134,12 +169,13 @@ namespace Mono.Data
                ///   <para>None.</para>\r
                /// </returns>\r
                /// <seealso cref='.ProviderCollection.Add'/>\r
-               public void AddRange(Provider[] value) \r
+               public void AddRange (Provider[] value) \r
                {\r
-                       for (int i = 0; (i < value.Length); i = (i + 1)) \r
-                       {\r
-                               this.Add(value[i]);\r
-                       }\r
+                       if (value == null) \r
+                               throw new System.ArgumentNullException ("value");\r
+\r
+                       for (int i = 0; i < value.Length; i++) \r
+                               this.Add (value [i]);\r
                }\r
                \r
                /// <summary>\r
@@ -156,10 +192,11 @@ namespace Mono.Data
                /// <seealso cref='.ProviderCollection.Add'/>\r
                public void AddRange(ProviderCollection value) \r
                {\r
+                       if (value == null) \r
+                               throw new System.ArgumentNullException ("value");\r
+\r
                        foreach (Provider p in value)\r
-                       {\r
-                               this.Add(p);\r
-                       }\r
+                               this.Add (p);\r
                }\r
                \r
                /// <summary>\r
@@ -172,9 +209,12 @@ namespace Mono.Data
                ///   otherwise, <see langword='false'/>.</para>\r
                /// </returns>\r
                /// <seealso cref='.ProviderCollection.IndexOf'/>\r
-               public bool Contains(Provider value) \r
+               public bool Contains (Provider value) \r
                {\r
-                       return Dictionary.Contains(value);\r
+                       if (value == null) \r
+                               throw new System.ArgumentNullException("value");\r
+\r
+                       return Dictionary.Contains (value);\r
                }\r
                \r
                /// <summary>\r
@@ -192,6 +232,9 @@ namespace Mono.Data
                /// <seealso cref='System.Array'/>\r
                public void CopyTo(Provider[] array, int index) \r
                {\r
+                       if (array == null) \r
+                               throw new System.ArgumentNullException ("array");\r
+\r
                        Dictionary.CopyTo(array, index);\r
                }\r
                \r
@@ -201,9 +244,9 @@ namespace Mono.Data
                /// </summary>\r
                /// <returns><para>None.</para></returns>\r
                /// <seealso cref='System.Collections.IEnumerator'/>\r
-               public new ProviderEnumerator GetEnumerator() \r
+               public new ProviderEnumerator GetEnumerator () \r
                {\r
-                       return new ProviderEnumerator(this);\r
+                       return new ProviderEnumerator (this);\r
                }\r
                \r
                /// <summary>\r
@@ -215,6 +258,9 @@ namespace Mono.Data
                /// <exception cref='System.ArgumentException'><paramref name='value'/> is not found in the Collection. </exception>\r
                public void Remove(Provider value) \r
                {\r
+                       if (value == null) \r
+                               throw new System.ArgumentNullException ("value");\r
+\r
                        Dictionary.Remove(value);\r
                }\r
                \r
@@ -227,6 +273,9 @@ namespace Mono.Data
                        \r
                        public ProviderEnumerator(ProviderCollection mappings) \r
                        {\r
+                               if (mappings == null) \r
+                                       throw new System.ArgumentNullException ("mappings");\r
+\r
                                this.temp = ((IEnumerable)(mappings));\r
                                this.baseEnumerator = temp.GetEnumerator();\r
                        }\r