2005-09-23 Chris Toshok <toshok@ximian.com>
[mono.git] / mcs / class / System.Configuration / System.Configuration / ConnectionStringSettings.cs
1 //
2 // System.Configuration.ConnectionStringSettings.cs
3 //
4 // Author:
5 //   Sureshkumar T <tsureshkumar@novell.com>
6 //
7 //
8 //
9 // Copyright (C) 2004 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 #if NET_2_0
32
33 #region Using directives
34
35 using System;
36
37 #endregion
38
39 namespace System.Configuration
40 {
41         public sealed class ConnectionStringSettings : ConfigurationElement
42         {
43
44                 #region Fields
45                 private static ConfigurationPropertyCollection _properties;
46         
47                 private static readonly ConfigurationProperty _propConnectionString;
48                 private static readonly ConfigurationProperty _propName;
49                 private static readonly ConfigurationProperty _propProviderName;
50                 #endregion // Fields
51
52                 #region Constructors
53                 static ConnectionStringSettings ()
54                 {
55                         _properties     = new ConfigurationPropertyCollection ();
56                         _propName = new ConfigurationProperty ("name", 
57                                                                typeof(string), 
58                                                                "", 
59                                                                ConfigurationPropertyOptions.IsRequired | 
60                                                                ConfigurationPropertyOptions.IsKey
61                                                                );
62
63                         _propProviderName = new ConfigurationProperty ("providerName",
64                                                                        typeof (string),
65                                                                        "",
66                                                                        ConfigurationPropertyOptions.IsRequired
67                                                                        );
68
69                         _propConnectionString = new ConfigurationProperty ("connectionString",
70                                                                            typeof (string),
71                                                                            "",
72                                                                            ConfigurationPropertyOptions.IsRequired
73                                                                            );
74
75                         _properties.Add (_propName);
76                         _properties.Add (_propProviderName);
77                         _properties.Add (_propConnectionString);
78                 }
79
80                 public ConnectionStringSettings ()
81                         : this (null, null, null)
82                 {
83                 }
84
85                 public ConnectionStringSettings (string name, string connectionString)
86                         : this (name, connectionString, null)
87                 {
88                 }
89
90                 public ConnectionStringSettings (string name, string connectionString, string providerName)
91                 {
92                         Name = name;
93                         ConnectionString = connectionString;
94                         ProviderName = providerName;
95                 }
96                 #endregion // Constructors
97
98                 #region Properties
99
100                 protected internal override ConfigurationPropertyCollection Properties
101                 {
102                         get
103                         {
104                                 return _properties;
105                         }
106                 }
107
108                 [ConfigurationProperty ("name", DefaultValue = "", Options = ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsKey)]
109                 public string Name
110                 {
111                         get { return (string) base [_propName];}
112                         set { base [_propName] = value; }
113                 }
114
115                 [ConfigurationProperty ("providerName", DefaultValue = "System.Data.SqlClient")]
116                 public string ProviderName
117                 {
118                         get { return (string) base [_propProviderName]; }
119                         set { base [_propProviderName] = value; }
120                 }
121
122                 [ConfigurationProperty ("connectionString", DefaultValue = "", Options = ConfigurationPropertyOptions.IsRequired)]
123                 public string ConnectionString
124                 {
125                         get { return (string) base [_propConnectionString]; }
126                         set { base [_propConnectionString] = value; }
127                 }
128        
129                 #endregion // Properties
130                 
131                 public override string ToString ()
132                 {
133                         return ConnectionString;
134                 }
135         }
136 }
137 #endif // NET_2_0