|
using System;
using System.Configuration;
using System.Xml;
using System.Xml.Serialization;
using System.Xml.XPath;
namespace Haack.Configuration
{
/// <summary>
/// Flexible configuration section handler that uses XML serialization
/// to convert XML within a config file into an object.
/// </summary>
/// <remarks>
/// <p>
/// Usage: In your config file, use the following to map a section of
/// the configuration file to the handler:</p>
/// <code>
/// <configuration>
/// <configSections>
/// <section name="MySection" type="Haack.Configuration.XmlSerializerSectionHandler, Haack.Configuration" />
/// </configSections>
/// </configuration>
/// </code>
/// <p>
/// The section should look something like:
/// <code>
/// <configuration>
/// <MySection type="NameSpace.MyConfigSettingObject, MyAssembly">
/// <Foo>1234</Foo>
/// <Bar>Blah</Bar>
/// <Quux>true</Quux>
/// </MySection>
/// </configuration>
/// </code>
/// </p>
/// <p>
/// Then you can obtain the section via: </p>
/// <code>ConfigurationSettings.GetConfig("MySection");</code>
/// <p>
/// And it will return an instance of the class "NameSpace.MyConfigSettingObject"
/// with the values from the config section.
/// </p>
/// <code>(MyConfigSettingObject)ConfigurationSettings.GetConfig("MySection");</code>
/// </remarks>
public class XmlSerializerSectionHandler : IConfigurationSectionHandler
{
public object Create(object parent, object context, XmlNode section)
{
return XmlSectionSettingsBase.LoadSettings(section);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.