In .:
[mono.git] / mcs / class / System.Configuration / System.Configuration / ProviderSettings.cs
1 //
2 // System.Configuration.ProviderSettings.cs
3 //
4 // Authors:
5 //      Duncan Mak (duncan@ximian.com)
6 //      Lluis Sanchez Gual (lluis@novell.com)
7 //      Chris Toshok (toshok@ximian.com)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 // 
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 // 
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28 // Copyright (C) 2004,2005 Novell, Inc (http://www.novell.com)
29 //
30
31 #if NET_2_0
32
33 using System;
34 using System.Xml;
35 using System.Collections.Specialized;
36
37 namespace System.Configuration
38 {
39         public sealed class ProviderSettings: ConfigurationElement
40         {
41                 ConfigNameValueCollection parameters;
42
43                 static ConfigurationProperty nameProp;
44                 static ConfigurationProperty typeProp;
45                 static ConfigurationPropertyCollection properties;
46
47                 static ProviderSettings ()
48                 {
49                         nameProp = new ConfigurationProperty ("name", typeof (string), null, ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsKey);
50                         typeProp = new ConfigurationProperty ("type", typeof (string), null, ConfigurationPropertyOptions.IsRequired);
51                         properties = new ConfigurationPropertyCollection ();
52
53                         properties.Add (nameProp);
54                         properties.Add (typeProp);
55                 }
56
57                 public ProviderSettings ()
58                 {
59                 }
60                 
61                 public ProviderSettings (string name, string type)
62                 {
63                         Name = name;
64                         Type = type;
65                 }
66                 
67                 protected override bool OnDeserializeUnrecognizedAttribute (string name, string value)
68                 {
69                         if (parameters == null)
70                                 parameters = new ConfigNameValueCollection ();
71                         parameters [name] = value;
72                         parameters.ResetModified ();
73                         return true;
74                 }
75
76                 protected internal override bool IsModified ()
77                 {
78                         return (parameters != null && parameters.IsModified) || base.IsModified ();
79                 }
80
81                 protected internal override void Reset (ConfigurationElement parentElement)
82                 {
83                         base.Reset (parentElement);
84
85                         ProviderSettings sec = parentElement as ProviderSettings;
86                         if (sec != null && sec.parameters != null)
87                                 parameters = new ConfigNameValueCollection (sec.parameters);
88                         else
89                                 parameters = null;
90                 }
91
92                 [MonoTODO]
93                 protected internal override void Unmerge (
94                                 ConfigurationElement source, ConfigurationElement parent,
95                                 ConfigurationSaveMode updateMode)
96                 {
97                         base.Unmerge (source, parent, updateMode);
98                 }
99                 
100                 [ConfigurationProperty ("name", Options = ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsKey)]
101                 public string Name {
102                         get { return (string) this [nameProp]; }
103                         set { this [nameProp] = value; }
104                 }
105                 
106                 [ConfigurationProperty ("type", Options = ConfigurationPropertyOptions.IsRequired)]
107                 public string Type {
108                         get { return (string) this [typeProp]; }
109                         set { this [typeProp] = value; }
110                 }
111
112                 protected internal override ConfigurationPropertyCollection Properties {
113                         get { return properties; }
114                 }
115                 
116                 public NameValueCollection Parameters {
117                         get {
118                                 if (parameters == null)
119                                         parameters = new ConfigNameValueCollection ();
120                                 return parameters;
121                         }
122                 }
123         }
124 }
125
126 #endif