2 // System.Configuration.AppSettingsSection.cs
5 // Duncan Mak (duncan@ximian.com)
6 // Chris Toshok (toshok@ximian.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)
32 using System.ComponentModel;
33 using System.Collections.Specialized;
37 namespace System.Configuration {
39 public sealed class AppSettingsSection : ConfigurationSection
41 private static ConfigurationPropertyCollection _properties;
42 private static readonly ConfigurationProperty _propFile;
43 private static readonly ConfigurationProperty _propSettings;
45 static AppSettingsSection ()
47 _propFile = new ConfigurationProperty ("file", typeof(string), "",
48 new StringConverter(), null, ConfigurationPropertyOptions.None);
49 _propSettings = new ConfigurationProperty ("", typeof(KeyValueConfigurationCollection), null,
50 null, null, ConfigurationPropertyOptions.IsDefaultCollection);
52 _properties = new ConfigurationPropertyCollection ();
54 _properties.Add (_propFile);
55 _properties.Add (_propSettings);
58 public AppSettingsSection ()
62 protected internal override bool IsModified ()
64 return Settings.IsModified ();
67 [MonoTODO ("file path? do we use a System.Configuration api for opening it? do we keep it open? do we open it writable?")]
68 protected internal override void DeserializeElement (XmlReader reader, bool serializeCollectionKey)
70 /* need to do this so we pick up the File attribute */
71 base.DeserializeElement (reader, serializeCollectionKey);
75 Stream s = System.IO.File.OpenRead (File);
76 XmlReader subreader = new XmlTextReader (s);
77 base.DeserializeElement (subreader, serializeCollectionKey);
81 // nada, we just ignore a missing/unreadble file
86 protected internal override void Reset (ConfigurationElement parentSection)
88 AppSettingsSection psec = parentSection as AppSettingsSection;
90 Settings.Reset (psec.Settings);
94 protected internal override string SerializeSection (
95 ConfigurationElement parent, string name, ConfigurationSaveMode mode)
98 return base.SerializeSection (parent, name, mode);
101 throw new NotImplementedException ();
105 [ConfigurationProperty ("file", DefaultValue = "")]
107 get { return (string)base [_propFile]; }
108 set { base [_propFile] = value; }
111 [ConfigurationProperty ("", Options = ConfigurationPropertyOptions.IsDefaultCollection)]
112 public KeyValueConfigurationCollection Settings {
113 get { return (KeyValueConfigurationCollection) base [_propSettings]; }
116 protected internal override ConfigurationPropertyCollection Properties {
122 protected internal override object GetRuntimeObject ()
124 KeyValueInternalCollection col = new KeyValueInternalCollection ();
126 foreach (string key in Settings.AllKeys) {
127 KeyValueConfigurationElement ele = Settings[key];
128 col.Add (ele.Key, ele.Value);
131 if (!ConfigurationManager.ConfigurationSystem.SupportsUserConfig)