//
// Authors:
// Duncan Mak (duncan@ximian.com)
-// Lluis Sanchez Gual (lluis@novell.com)
+// Lluis Sanchez Gual (lluis@novell.com)
+// Martin Baulig <martin.baulig@xamarin.com>
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (c) 2012 Xamarin Inc. (http://www.xamarin.com)
//
-#if NET_2_0
using System.Collections;
using System.Xml;
using System.IO;
// ignore, it can fail - we deserialize only in order to get
// the configSource attribute
}
- XmlDocument doc = new XmlDocument ();
+ XmlDocument doc = new ConfigurationXmlDocument ();
doc.LoadXml (RawXml);
return SectionHandler.Create (parent, ConfigContext, doc.DocumentElement);
}
{
ConfigurationElement elem = (ConfigurationElement) Activator.CreateInstance (t);
elem.Init ();
+ elem.Configuration = Configuration;
if (IsReadOnly ())
elem.SetReadOnly ();
return elem;
{
if (protection_provider != null) {
ProtectedConfigurationProvider prov = ProtectedConfiguration.GetProvider (protection_provider, true);
- XmlDocument doc = new XmlDocument ();
+ XmlDocument doc = new ConfigurationXmlDocument ();
reader.MoveToElement ();
[MonoInternalNote ("find the proper location for the decryption stuff")]
protected internal virtual void DeserializeSection (XmlReader reader)
{
- DoDeserializeSection (reader);
+ try
+ {
+ DoDeserializeSection (reader);
+ }
+ catch (ConfigurationErrorsException ex)
+ {
+ throw new ConfigurationErrorsException(String.Format("Error deserializing configuration section {0}: {1}", this.SectionInformation.Name, ex.Message));
+ }
}
internal void DeserializeConfigSource (string basePath)
return;
if (Path.IsPathRooted (config_source))
- throw new ConfigurationException ("The configSource attribute must be a relative physical path.");
+ throw new ConfigurationErrorsException ("The configSource attribute must be a relative physical path.");
if (HasLocalModifications ())
- throw new ConfigurationException ("A section using 'configSource' may contain no other attributes or elements.");
+ throw new ConfigurationErrorsException ("A section using 'configSource' may contain no other attributes or elements.");
string path = Path.Combine (basePath, config_source);
if (!File.Exists (path)) {
RawXml = null;
SectionInformation.SetRawXml (null);
- return;
+ throw new ConfigurationErrorsException (string.Format ("Unable to open configSource file '{0}'.", path));
}
RawXml = File.ReadAllText (path);
SectionInformation.SetRawXml (RawXml);
DeserializeElement (new ConfigXmlTextReader (new StringReader (RawXml), path), false);
}
-
+
protected internal virtual string SerializeSection (ConfigurationElement parentElement, string name, ConfigurationSaveMode saveMode)
{
externalDataXml = null;
}
else
elem = this;
-
+
+ /*
+ * FIXME: LAMESPEC
+ *
+ * Cache the current values of 'parentElement' and 'saveMode' for later use in
+ * ConfigurationElement.SerializeToXmlElement().
+ *
+ */
+ elem.PrepareSave (parentElement, saveMode);
+ bool hasValues = elem.HasValues (parentElement, saveMode);
+
string ret;
using (StringWriter sw = new StringWriter ()) {
using (XmlTextWriter tw = new XmlTextWriter (sw)) {
tw.Formatting = Formatting.Indented;
- elem.SerializeToXmlElement (tw, name);
+ if (hasValues)
+ elem.SerializeToXmlElement (tw, name);
+ else if ((saveMode == ConfigurationSaveMode.Modified) && elem.IsModified ()) {
+ // MS emits an empty section element.
+ tw.WriteStartElement (name);
+ tw.WriteEndElement ();
+ }
tw.Close ();
}
}
}
}
-#endif
+