Author: mhabersack
Date: 2008-02-20 14:49:13 -0500 (Wed, 20 Feb 2008)
New Revision: 96297

Modified:
   
branches/mono-1-9/mcs/class/System.Configuration/System.Configuration/ChangeLog
   
branches/mono-1-9/mcs/class/System.Configuration/System.Configuration/ConfigurationElement.cs
   
branches/mono-1-9/mcs/class/System.Configuration/System.Configuration/ConfigurationSection.cs
Log:
Backport of r96296


Modified: 
branches/mono-1-9/mcs/class/System.Configuration/System.Configuration/ChangeLog
===================================================================
--- 
branches/mono-1-9/mcs/class/System.Configuration/System.Configuration/ChangeLog 
    2008-02-20 19:46:40 UTC (rev 96296)
+++ 
branches/mono-1-9/mcs/class/System.Configuration/System.Configuration/ChangeLog 
    2008-02-20 19:49:13 UTC (rev 96297)
@@ -1,3 +1,14 @@
+2008-02-20  Marek Habersack  <[EMAIL PROTECTED]>
+
+       * ConfigurationSection.cs: support the "configSource" attribute
+       when deserializing a section. Contents of the file (if it exists)
+       replaces the previous section contents.
+
+       * ConfigurationElement.cs: ignore the "configSource" attribute if we're 
a
+       ConfigurationSection instance.
+       HasValues () returns true only if any of the properties has the
+       origin set to SetHere.
+
 2008-01-16  Zoltan Varga  <[EMAIL PROTECTED]>
 
        * ConfigurationElement.cs: Allow non-public constructors. Fixes #353554.

Modified: 
branches/mono-1-9/mcs/class/System.Configuration/System.Configuration/ConfigurationElement.cs
===================================================================
--- 
branches/mono-1-9/mcs/class/System.Configuration/System.Configuration/ConfigurationElement.cs
       2008-02-20 19:46:40 UTC (rev 96296)
+++ 
branches/mono-1-9/mcs/class/System.Configuration/System.Configuration/ConfigurationElement.cs
       2008-02-20 19:49:13 UTC (rev 96297)
@@ -269,8 +269,9 @@
                internal virtual bool HasValues ()
                {
                        foreach (PropertyInformation pi in 
ElementInformation.Properties)
-                               if (pi.ValueOrigin != 
PropertyValueOrigin.Default)
+                               if (pi.ValueOrigin == 
PropertyValueOrigin.SetHere)
                                        return true;
+                       
                        return false;
                }
                
@@ -301,8 +302,9 @@
                                        }
                                        else if (reader.LocalName == "xmlns") {
                                                /* ignore */
-                                       }
-                                       else if 
(!OnDeserializeUnrecognizedAttribute (reader.LocalName, reader.Value))
+                                       } else if (this is ConfigurationSection 
&& reader.LocalName == "configSource") {
+                                               /* ignore */
+                                       } else if 
(!OnDeserializeUnrecognizedAttribute (reader.LocalName, reader.Value))
                                                throw new 
ConfigurationException ("Unrecognized attribute '" + reader.LocalName + "'.");
 
                                        continue;

Modified: 
branches/mono-1-9/mcs/class/System.Configuration/System.Configuration/ConfigurationSection.cs
===================================================================
--- 
branches/mono-1-9/mcs/class/System.Configuration/System.Configuration/ConfigurationSection.cs
       2008-02-20 19:46:40 UTC (rev 96296)
+++ 
branches/mono-1-9/mcs/class/System.Configuration/System.Configuration/ConfigurationSection.cs
       2008-02-20 19:49:13 UTC (rev 96297)
@@ -45,7 +45,7 @@
                protected ConfigurationSection ()
                {
                }
-
+               
                internal IConfigurationSectionHandler SectionHandler {
                        get { return section_handler; }
                        set { section_handler = value; }
@@ -101,15 +101,21 @@
                {
                        reader.MoveToContent ();
 
+                       string protection_provider = null;
+                       string config_source = null;
+                       string localName;
+                       
+                       while (reader.MoveToNextAttribute ()) {
+                               localName = reader.LocalName;
+                               
+                               if (localName == "configProtectionProvider")
+                                       protection_provider = reader.Value;
+                               else if (localName == "configSource")
+                                       config_source = reader.Value;
+                       }
+
                        /* XXX this stuff shouldn't be here */
                        {
-                               string protection_provider = null;
-
-                               while (reader.MoveToNextAttribute ()) {
-                                       if (reader.LocalName == 
"configProtectionProvider")
-                                               protection_provider = 
reader.Value;
-                               }
-
                                if (protection_provider != null) {
                                        ProtectedConfigurationProvider prov = 
ProtectedConfiguration.GetProvider (protection_provider, true);
                                        XmlDocument doc = new XmlDocument ();
@@ -128,8 +134,24 @@
                                }
                        }
 
+                       XmlReader r = reader;
+                       if (config_source != null) {
+                               if (config_source.Length == 0 || 
Path.IsPathRooted (config_source))
+                                       throw new ConfigurationException ("The 
configSource attribute must be a relative physical path.");
+                               
+                               if (HasValues ())
+                                       throw new ConfigurationException ("A 
section using 'configSource' may contain no other attributes or elements.");
+                               
+                               SectionInformation.ConfigSource = config_source;
+                               if (File.Exists (config_source)) {
+                                       RawXml = File.ReadAllText 
(config_source);
+                                       r = new XmlTextReader (new StringReader 
(RawXml));
+                               } else
+                                       RawXml = null;
+                       }
+                               
                        SectionInformation.SetRawXml (RawXml);
-                       DeserializeElement (reader, false);
+                       DeserializeElement (r, false);
                }
 
                protected internal virtual string SerializeSection 
(ConfigurationElement parentElement, string name, ConfigurationSaveMode 
saveMode)

_______________________________________________
Mono-patches maillist  -  Mono-patches@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to