Merge pull request #268 from pcc/menudeactivate
[mono.git] / mcs / class / System.Configuration / System.Configuration / ConnectionStringSettings.cs
1 //
2 // System.Configuration.ConnectionStringSettings.cs
3 //
4 // Authors:
5 //   Sureshkumar T <tsureshkumar@novell.com>
6 //   Chris Toshok <toshok@ximian.com>
7 //
8 //
9 // Copyright (C) 2004,2005 Novell, Inc (http://www.novell.com)
10 //
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:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
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.
29 //
30
31 using System;
32 using System.ComponentModel;
33
34 namespace System.Configuration
35 {
36         public sealed class ConnectionStringSettings : ConfigurationElement
37         {
38                 private static ConfigurationPropertyCollection _properties;
39         
40                 private static readonly ConfigurationProperty _propConnectionString;
41                 private static readonly ConfigurationProperty _propName;
42                 private static readonly ConfigurationProperty _propProviderName;
43
44                 static ConnectionStringSettings ()
45                 {
46                         _properties     = new ConfigurationPropertyCollection ();
47                         _propName = new ConfigurationProperty ("name", typeof(string), null,
48                                                                TypeDescriptor.GetConverter (typeof (string)),
49                                                                null,
50                                                                ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsKey);
51
52                         _propProviderName = new ConfigurationProperty ("providerName", typeof (string), "",
53                                                                        ConfigurationPropertyOptions.None);
54
55                         _propConnectionString = new ConfigurationProperty ("connectionString", typeof (string), "",
56                                                                            ConfigurationPropertyOptions.IsRequired);
57
58                         _properties.Add (_propName);
59                         _properties.Add (_propProviderName);
60                         _properties.Add (_propConnectionString);
61                 }
62
63                 public ConnectionStringSettings ()
64                 {
65                 }
66
67                 public ConnectionStringSettings (string name, string connectionString)
68                         : this (name, connectionString, "")
69                 {
70                 }
71
72                 public ConnectionStringSettings (string name, string connectionString, string providerName)
73                 {
74                         Name = name;
75                         ConnectionString = connectionString;
76                         ProviderName = providerName;
77                 }
78
79                 protected internal override ConfigurationPropertyCollection Properties
80                 {
81                         get { return _properties; }
82                 }
83
84                 [ConfigurationProperty ("name", DefaultValue = "", Options = ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsKey)]
85                 public string Name
86                 {
87                         get { return (string) base [_propName];}
88                         set { base [_propName] = value; }
89                 }
90
91                 [ConfigurationProperty ("providerName", DefaultValue = "System.Data.SqlClient")]
92                 public string ProviderName
93                 {
94                         get { return (string) base [_propProviderName]; }
95                         set { base [_propProviderName] = value; }
96                 }
97
98                 [ConfigurationProperty ("connectionString", DefaultValue = "", Options = ConfigurationPropertyOptions.IsRequired)]
99                 public string ConnectionString
100                 {
101                         get { return (string) base [_propConnectionString]; }
102                         set { base [_propConnectionString] = value; }
103                 }
104                 
105                 public override string ToString ()
106                 {
107                         return ConnectionString;
108                 }
109         }
110 }
111