2005-06-14 Lluis Sanchez Gual <lluis@novell.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                 private static ConfigurationPropertyCollection _keyProperties;
47         
48                 private static readonly ConfigurationProperty _propConnectionString;
49                 private static readonly ConfigurationProperty _propName;
50                 private static readonly ConfigurationProperty _propProviderName;
51                 #endregion // Fields
52
53                 #region Constructors
54                 static ConnectionStringSettings ()
55                 {
56                         _properties     = new ConfigurationPropertyCollection ();
57                         _keyProperties  = new ConfigurationPropertyCollection ();
58                         _propName = new ConfigurationProperty ("name", 
59                                                                typeof(string), 
60                                                                "", 
61                                                                ConfigurationPropertyFlags.Required | 
62                                                                ConfigurationPropertyFlags.IsKey
63                                                                );
64
65                         _propProviderName = new ConfigurationProperty ("providerName",
66                                                                        typeof (string),
67                                                                        "",
68                                                                        ConfigurationPropertyFlags.Required
69                                                                        );
70
71                         _propConnectionString = new ConfigurationProperty ("connectionString",
72                                                                            typeof (string),
73                                                                            "",
74                                                                            ConfigurationPropertyFlags.Required
75                                                                            );
76
77                         _properties.Add (_propName);
78                         _properties.Add (_propProviderName);
79                         _properties.Add (_propConnectionString);
80
81                         _keyProperties.Add (_propName);
82                 }
83
84                 public ConnectionStringSettings ()
85                         : this (null, null, null)
86                 {
87                 }
88
89                 public ConnectionStringSettings (string name, string connectionString)
90                         : this (name, connectionString, null)
91                 {
92                 }
93
94                 public ConnectionStringSettings (string name, string connectionString, string providerName)
95                 {
96                         Name = name;
97                         ConnectionString = connectionString;
98                         ProviderName = providerName;
99                 }
100                 #endregion // Constructors
101
102                 #region Properties
103
104                 protected internal override ConfigurationPropertyCollection CollectionKeyProperties
105                 {
106                         get
107                         {
108                                 return _keyProperties;
109                         }
110                 }
111                 protected internal override ConfigurationPropertyCollection Properties
112                 {
113                         get
114                         {
115                                 return _properties;
116                         }
117                 }
118                 public string Name
119                 {
120                         get { return (string) base [_propName];}
121                         set { base [_propName] = value; }
122                 }
123
124                 public string ProviderName
125                 {
126                         get { return (string) base [_propProviderName]; }
127                         set { base [_propProviderName] = value; }
128                 }
129
130                 public string ConnectionString
131                 {
132                         get { return (string) base [_propConnectionString]; }
133                         set { base [_propConnectionString] = value; }
134                 }
135        
136                 #endregion // Properties
137         }
138
139
140 }
141 #endif // NET_2_0