Merge pull request #600 from tr8dr/master
[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 using System;
32 using System.Xml;
33 using System.Collections.Specialized;
34
35 namespace System.Configuration
36 {
37         public sealed class ProviderSettings: ConfigurationElement
38         {
39                 ConfigNameValueCollection parameters;
40
41                 static ConfigurationProperty nameProp;
42                 static ConfigurationProperty typeProp;
43                 static ConfigurationPropertyCollection properties;
44
45                 static ProviderSettings ()
46                 {
47                         nameProp = new ConfigurationProperty ("name", typeof (string), null, ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsKey);
48                         typeProp = new ConfigurationProperty ("type", typeof (string), null, ConfigurationPropertyOptions.IsRequired);
49                         properties = new ConfigurationPropertyCollection ();
50
51                         properties.Add (nameProp);
52                         properties.Add (typeProp);
53                 }
54
55                 public ProviderSettings ()
56                 {
57                 }
58                 
59                 public ProviderSettings (string name, string type)
60                 {
61                         Name = name;
62                         Type = type;
63                 }
64                 
65                 protected override bool OnDeserializeUnrecognizedAttribute (string name, string value)
66                 {
67                         if (parameters == null)
68                                 parameters = new ConfigNameValueCollection ();
69                         parameters [name] = value;
70                         parameters.ResetModified ();
71                         return true;
72                 }
73
74                 protected internal override bool IsModified ()
75                 {
76                         return (parameters != null && parameters.IsModified) || base.IsModified ();
77                 }
78
79                 protected internal override void Reset (ConfigurationElement parentElement)
80                 {
81                         base.Reset (parentElement);
82
83                         ProviderSettings sec = parentElement as ProviderSettings;
84                         if (sec != null && sec.parameters != null)
85                                 parameters = new ConfigNameValueCollection (sec.parameters);
86                         else
87                                 parameters = null;
88                 }
89
90                 [MonoTODO]
91                 protected internal override void Unmerge (
92                                 ConfigurationElement source, ConfigurationElement parent,
93                                 ConfigurationSaveMode updateMode)
94                 {
95                         base.Unmerge (source, parent, updateMode);
96                 }
97                 
98                 [ConfigurationProperty ("name", Options = ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsKey)]
99                 public string Name {
100                         get { return (string) this [nameProp]; }
101                         set { this [nameProp] = value; }
102                 }
103                 
104                 [ConfigurationProperty ("type", Options = ConfigurationPropertyOptions.IsRequired)]
105                 public string Type {
106                         get { return (string) this [typeProp]; }
107                         set { this [typeProp] = value; }
108                 }
109
110                 protected internal override ConfigurationPropertyCollection Properties {
111                         get { return properties; }
112                 }
113                 
114                 public NameValueCollection Parameters {
115                         get {
116                                 if (parameters == null)
117                                         parameters = new ConfigNameValueCollection ();
118                                 return parameters;
119                         }
120                 }
121         }
122 }
123