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.
33 namespace System.Configuration
35 [ConfigurationCollection (typeof (ConnectionStringSettings),
36 CollectionType = ConfigurationElementCollectionType.AddRemoveClearMap)]
37 public sealed class ConnectionStringSettingsCollection : ConfigurationElementCollection
40 public ConnectionStringSettingsCollection () : base ()
44 public new ConnectionStringSettings this [string Name]
47 foreach (ConfigurationElement c in this) {
48 if (!(c is ConnectionStringSettings))
50 if (string.Compare(((ConnectionStringSettings) c).Name, Name, true,
51 System.Globalization.CultureInfo.InvariantCulture) == 0)
52 return c as ConnectionStringSettings;
59 public ConnectionStringSettings this [int index]
61 get { return (ConnectionStringSettings) BaseGet (index); }
63 if (BaseGet (index) != null)
65 BaseAdd (index, value);
70 protected internal override ConfigurationPropertyCollection Properties {
71 get { return base.Properties; }
75 protected override ConfigurationElement CreateNewElement ()
77 return new ConnectionStringSettings ();
80 protected override object GetElementKey (ConfigurationElement element)
82 return ((ConnectionStringSettings) element).Name;
85 public void Add (ConnectionStringSettings settings)
87 BaseAdd ((ConfigurationElement) settings);
95 public int IndexOf (ConnectionStringSettings settings)
97 return BaseIndexOf (settings);
100 public void Remove (ConnectionStringSettings settings)
102 BaseRemove (settings.Name);
105 public void Remove (string name)
110 public void RemoveAt (int index)
112 BaseRemoveAt (index);
115 protected override void BaseAdd (int index, ConfigurationElement element)
117 if (!(element is ConnectionStringSettings))
118 base.BaseAdd (element);
119 if (IndexOf ((ConnectionStringSettings) element) >= 0)
120 throw new ConfigurationErrorsException (String.Format ("The element {0} already exist!",
121 ((ConnectionStringSettings) element).Name));
122 this [index] = (ConnectionStringSettings) element;