2 // System.Configuration.ConnectionStringSettingsCollection.cs
5 // Sureshkumar T <tsureshkumar@novell.com>
6 // Chris Toshok <toshok@ximian.com>
9 // Copyright (C) 2004,2005 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 namespace System.Configuration
37 [ConfigurationCollection (typeof (ConnectionStringSettings),
38 CollectionType = ConfigurationElementCollectionType.AddRemoveClearMap)]
39 public sealed class ConnectionStringSettingsCollection : ConfigurationElementCollection
42 public ConnectionStringSettingsCollection () : base ()
46 public new ConnectionStringSettings this [string Name]
49 foreach (ConfigurationElement c in this) {
50 if (!(c is ConnectionStringSettings))
52 if (string.Compare(((ConnectionStringSettings) c).Name, Name, true,
53 System.Globalization.CultureInfo.InvariantCulture) == 0)
54 return c as ConnectionStringSettings;
61 public new ConnectionStringSettings this [int index]
63 get { return (ConnectionStringSettings) BaseGet (index); }
65 if (BaseGet (index) != null)
67 BaseAdd (index, value);
72 protected internal override ConfigurationPropertyCollection Properties {
73 get { return base.Properties; }
77 protected override ConfigurationElement CreateNewElement ()
79 return new ConnectionStringSettings ();
82 protected override object GetElementKey (ConfigurationElement element)
84 return ((ConnectionStringSettings) element).Name;
87 public void Add (ConnectionStringSettings settings)
89 BaseAdd ((ConfigurationElement) settings);
97 public int IndexOf (ConnectionStringSettings settings)
99 return BaseIndexOf (settings);
102 public void Remove (ConnectionStringSettings settings)
104 BaseRemove (settings.Name);
107 public void Remove (string name)
112 public void RemoveAt (int index)
114 BaseRemoveAt (index);
117 protected override void BaseAdd (int index, ConfigurationElement element)
119 if (!(element is ConnectionStringSettings))
120 base.BaseAdd (element);
121 if (IndexOf ((ConnectionStringSettings) element) >= 0)
122 throw new ConfigurationException (String.Format ("The element {0} already exist!",
123 ((ConnectionStringSettings) element).Name));
124 this [index] = (ConnectionStringSettings) element;