proper handling of <configSections>
authorMarek Habersack <grendel@twistedcode.net>
Tue, 28 Nov 2006 20:26:56 +0000 (20:26 -0000)
committerMarek Habersack <grendel@twistedcode.net>
Tue, 28 Nov 2006 20:26:56 +0000 (20:26 -0000)
svn path=/trunk/mcs/; revision=68615

mcs/class/System.Configuration/System.Configuration/ChangeLog
mcs/class/System.Configuration/System.Configuration/ConfigInfo.cs
mcs/class/System.Configuration/System.Configuration/SectionGroupInfo.cs
mcs/class/System.Configuration/System.Configuration/SectionInfo.cs

index abca1e551390594ec8bb293ebce7a883ba64744c..a1461aa5bcc90fecb64fdf461e07689c855639ae 100644 (file)
@@ -1,3 +1,12 @@
+2006-11-28  Marek Habersack  <grendello@gmail.com>
+
+       * SectionGroupInfo.cs: Implement merging of section groups with
+       the same names and parents.
+
+       * ConfigInfo.cs: Add an abstract method for merging sections.
+
+       * SectionInfo.cs: Add implementation of an abstract base method
+
 2006-08-23  Konstantin Triger <kostat@mainsoft.com>
 
        * SectionInfo.cs: refactoring - remove unneeded bool? usage.
index ea971689b3d33b0ece8df98062636b04e832996e..fe127d9e2f30b8e2214584e7d8ccb485a182f06a 100644 (file)
@@ -80,6 +80,8 @@ namespace System.Configuration {
                public abstract void WriteConfig (Configuration cfg, XmlWriter writer, ConfigurationSaveMode mode);
                public abstract void ReadData (Configuration config, XmlTextReader reader, bool overrideAllowed);
                public abstract void WriteData (Configuration config, XmlWriter writer, ConfigurationSaveMode mode);
+               
+               internal abstract void Merge (ConfigInfo data);
        }
 }
 
index 0696fae8e36a7e4e1e4cec660e74ab99ebbca3e3..58fa2612bf52364e1c31d19c194bc2e0f2bb6924 100644 (file)
@@ -198,9 +198,9 @@ namespace System.Configuration
 
                                if (name == "section")
                                        cinfo = new SectionInfo ();
-                               else if (name == "sectionGroup")
+                               else if (name == "sectionGroup") {
                                        cinfo = new SectionGroupInfo ();
-                               else
+                               else
                                        ThrowException ("Unrecognized element: " + reader.Name, reader);
                                        
                                cinfo.ReadConfig (cfg, streamName, reader);
@@ -210,6 +210,9 @@ namespace System.Configuration
                                if (actInfo != null) {
                                        if (actInfo.GetType () != cinfo.GetType ())
                                                ThrowException ("A section or section group named '" + cinfo.Name + "' already exists", reader);
+                                       // Merge all the new data
+                                       actInfo.Merge (cinfo);
+                                       
                                        // Make sure that this section is saved in this configuration file:
                                        actInfo.StreamName = streamName;
                                }
@@ -340,9 +343,33 @@ namespace System.Configuration
                                if (data != null)
                                        return data;
                        }
+                       // It might be in the root section group
                        return null;
                }
 
+               internal override void Merge (ConfigInfo newData)
+               {
+                       SectionGroupInfo data = newData as SectionGroupInfo;
+                       if (data == null)
+                               return;
+                       ConfigInfo actInfo;
+                       if (data.sections != null && data.sections.Count > 0)
+                               foreach (string key in data.sections.AllKeys) {
+                                       actInfo = sections[key];
+                                       if (actInfo != null)
+                                               continue;
+                                       sections.Add (key, data.sections[key]);
+                               }
+                       
+                       if (data.groups != null && data.sections.Count > 0)
+                               foreach (string key in data.groups.AllKeys) {
+                                       actInfo = groups[key];
+                                       if (actInfo != null)
+                                               continue;
+                                       groups.Add (key, data.groups[key]);
+                               }
+               }
+               
                public void WriteRootData (XmlWriter writer, Configuration config, ConfigurationSaveMode mode)
                {
                        WriteContent (writer, config, mode, false);
index 91f2b6cb818dc07fd393d555ab9a172b4b30b272..8ea69b8edcd6a32a234ed46d91f16f88a2c94186 100644 (file)
@@ -207,6 +207,9 @@ namespace System.Configuration
                                tr.Close ();*/
                        }
                }
+               
+               internal override void Merge (ConfigInfo data)
+               {}
        }
 }