Merge pull request #364 from directhex/master
[mono.git] / mcs / class / System.Configuration / System.Configuration / AppSettingsSection.cs
index c07550f0f37941d92fe23edc4a7ca2ce822c9d7d..1008a0ae986c214146c513f2320112e183479032 100644 (file)
@@ -29,6 +29,7 @@
 
 #if NET_2_0
 using System;
+using System.ComponentModel;
 using System.Collections.Specialized;
 using System.Xml;
 using System.IO;
@@ -43,14 +44,10 @@ namespace System.Configuration {
 
                 static AppSettingsSection ()
                 {
-                        _propFile = new ConfigurationProperty ("file",
-                                                               typeof(string), 
-                                                               "", 
-                                                               ConfigurationPropertyOptions.None);
-                        _propSettings = new ConfigurationProperty ("",
-                                                                  typeof(KeyValueConfigurationCollection),
-                                                                  null, 
-                                                                  ConfigurationPropertyOptions.IsDefaultCollection);
+                        _propFile = new ConfigurationProperty ("file", typeof(string), "",
+                                                              new StringConverter(), null, ConfigurationPropertyOptions.None);
+                        _propSettings = new ConfigurationProperty ("", typeof(KeyValueConfigurationCollection), null, 
+                                                                  null, null, ConfigurationPropertyOptions.IsDefaultCollection);
 
                         _properties     = new ConfigurationPropertyCollection ();
 
@@ -67,14 +64,22 @@ namespace System.Configuration {
                        return Settings.IsModified ();
                }
 
-               [MonoTODO ("Read file attribute")]
+               [MonoInternalNote ("file path?  do we use a System.Configuration api for opening it?  do we keep it open?  do we open it writable?")]
                protected internal override void DeserializeElement (XmlReader reader, bool serializeCollectionKey)
                {
+                       /* need to do this so we pick up the File attribute */
                        base.DeserializeElement (reader, serializeCollectionKey);
 
                        if (File != "") {
-                               /* deserialize from the file */
-                               throw new NotImplementedException ();
+                               try {
+                                       Stream s = System.IO.File.OpenRead (File);
+                                       XmlReader subreader = new ConfigXmlTextReader (s, File);
+                                       base.DeserializeElement (subreader, serializeCollectionKey);
+                                       s.Close ();
+                               }
+                               catch {
+                                       // nada, we just ignore a missing/unreadble file
+                               }
                        }
                }
 
@@ -114,10 +119,19 @@ namespace System.Configuration {
                        }
                }
 
-               [MonoTODO]
                protected internal override object GetRuntimeObject ()
                {
-                       return base.GetRuntimeObject();
+                       KeyValueInternalCollection col = new KeyValueInternalCollection ();
+                               
+                       foreach (string key in Settings.AllKeys) {
+                               KeyValueConfigurationElement ele = Settings[key];
+                               col.Add (ele.Key, ele.Value);
+                       }
+                               
+                       if (!ConfigurationManager.ConfigurationSystem.SupportsUserConfig)
+                               col.SetReadOnly ();
+
+                       return col;
                }
        }
 }