${StandardHeader.C#}
using System;
using System.Configuration;
namespace ${StandardNamespace}
{
///
/// Configuration section <${ClassName}>
///
///
/// Assign properties to your child class that has the attribute
/// [ConfigurationProperty] to store said properties in the xml.
///
public sealed class ${ClassName}Settings : ConfigurationSection
{
System.Configuration.Configuration _Config;
#region ConfigurationProperties
/*
* Uncomment the following section and add a Configuration Collection
* from the with the file named ${ClassName}.cs
*/
// ///
// /// A custom XML section for an application's configuration file.
// ///
// [ConfigurationProperty("customSection", IsDefaultCollection = true)]
// public ${ClassName}Collection ${ClassName}
// {
// get { return (${ClassName}Collection) base["customSection"]; }
// }
///
/// Collection of ${ClassName}Element(s)
/// A custom XML section for an applications configuration file.
///
[ConfigurationProperty("exampleAttribute", DefaultValue="exampleValue")]
public string ExampleAttribute {
get { return (string) this["exampleAttribute"]; }
set { this["exampleAttribute"] = value; }
}
#endregion
///
/// Private Constructor used by our factory method.
///
private ${ClassName}Settings () : base () {
// Allow this section to be stored in user.app. By default this is forbidden.
this.SectionInformation.AllowExeDefinition =
ConfigurationAllowExeDefinition.MachineToLocalUser;
}
#region Public Methods
///
/// Saves the configuration to the config file.
///
public void Save() {
_Config.Save();
}
#endregion
#region Static Members
///
/// Gets the current applications <${ClassName}> section.
///
///
/// The <ConfigurationUserLevel> that the config file
/// is retrieved from.
///
///
/// The configuration file's <${ClassName}> section.
///
public static ${ClassName}Settings GetSection (ConfigurationUserLevel ConfigLevel) {
/*
* This class is setup using a factory pattern that forces you to
* name the section <${ClassName}> in the config file.
* If you would prefer to be able to specify the name of the section,
* then remove this method and mark the constructor public.
*/
System.Configuration.Configuration Config = ConfigurationManager.OpenExeConfiguration
(ConfigLevel);
${ClassName}Settings o${ClassName}Settings;
o${ClassName}Settings =
(${ClassName}Settings)Config.GetSection("${ClassName}Settings");
if (o${ClassName}Settings == null) {
o${ClassName}Settings = new ${ClassName}Settings();
Config.Sections.Add("${ClassName}Settings", o${ClassName}Settings);
}
o${ClassName}Settings._Config = Config;
return o${ClassName}Settings;
}
#endregion
}
}