2 // System.Configuration.ConfigurationSection.cs
5 // Duncan Mak (duncan@ximian.com)
6 // Lluis Sanchez Gual (lluis@novell.com)
8 // Permission is hereby granted, free of charge, to any person obtaining
9 // a copy of this software and associated documentation files (the
10 // "Software"), to deal in the Software without restriction, including
11 // without limitation the rights to use, copy, modify, merge, publish,
12 // distribute, sublicense, and/or sell copies of the Software, and to
13 // permit persons to whom the Software is furnished to do so, subject to
14 // the following conditions:
16 // The above copyright notice and this permission notice shall be
17 // included in all copies or substantial portions of the Software.
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
31 using System.Collections;
35 using System.Security.Cryptography.Xml;
38 namespace System.Configuration
40 public abstract class ConfigurationSection : ConfigurationElement
42 SectionInformation sectionInformation;
43 IConfigurationSectionHandler section_handler;
45 protected ConfigurationSection ()
49 internal IConfigurationSectionHandler SectionHandler {
50 get { return section_handler; }
51 set { section_handler = value; }
55 public SectionInformation SectionInformation {
57 if (sectionInformation == null)
58 sectionInformation = new SectionInformation ();
59 return sectionInformation;
64 protected internal virtual object GetRuntimeObject ()
66 // FIXME: this hack is nasty. We should make some
67 // refactory on the entire assembly.
68 if (SectionHandler != null) {
71 XmlDocument doc = new XmlDocument ();
73 return SectionHandler.Create (null, null, doc.DocumentElement);
79 protected internal override bool IsModified ()
81 return base.IsModified ();
85 protected internal override void ResetModified ()
87 base.ResetModified ();
90 ConfigurationElement CreateElement (Type t)
92 ConfigurationElement elem = (ConfigurationElement) Activator.CreateInstance (t);
99 [MonoTODO ("find the proper location for the decryption stuff")]
100 protected internal virtual void DeserializeSection (XmlReader reader)
102 reader.MoveToContent ();
104 /* XXX this stuff shouldn't be here */
106 string protection_provider = null;
108 while (reader.MoveToNextAttribute ()) {
109 if (reader.LocalName == "configProtectionProvider")
110 protection_provider = reader.Value;
113 if (protection_provider != null) {
114 ProtectedConfigurationProvider prov = ProtectedConfiguration.GetProvider (protection_provider, true);
115 XmlDocument doc = new XmlDocument ();
117 reader.MoveToElement ();
119 doc.Load (new StringReader (reader.ReadInnerXml ()));
121 XmlNode n = prov.Decrypt (doc);
123 reader = new XmlNodeReader (n);
125 SectionInformation.ProtectSection (protection_provider);
127 reader.MoveToContent ();
131 SectionInformation.SetRawXml (RawXml);
132 DeserializeElement (reader, false);
135 protected internal virtual string SerializeSection (ConfigurationElement parentElement, string name, ConfigurationSaveMode saveMode)
137 ConfigurationElement elem;
138 if (parentElement != null) {
139 elem = (ConfigurationElement) CreateElement (GetType());
140 elem.Unmerge (this, parentElement, saveMode);
145 StringWriter sw = new StringWriter ();
146 XmlTextWriter tw = new XmlTextWriter (sw);
147 tw.Formatting = Formatting.Indented;
148 elem.SerializeToXmlElement (tw, name);
150 return sw.ToString ();