Custom configuration setting
using System;
using MyNamespace;
namespace MyNamespace
{
public class MySettings
{
public float Foo
{
get { return this.foo; }
set { this.foo = value; }
}
float foo;
public string Bar
{
get { return this.bar; }
set { this.bar = value; }
}
string bar;
const string SECTION_NAME = "MyStuff";
static MySettings _settings = (MySettings)System.Configuration.ConfigurationManager.GetSection("MySettings");
public static MySettings Settings
{
get
{
return _settings;
}
}
}
}
File: Web.config
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="MySettings" type="Configuration.XmlSerializerSectionHandler, ConfigurationExamples"/>
<section name="MySection" type="Configuration.MySection, ConfigurationExamples" />
</configSections>
<appSettings>
<add key="MySetting" value="MyValue"/>
<add key="AnotherSetting" value="AnotherValue"/>
</appSettings>
<MySettings type="MyNamespace.MySettings, ConfigurationExamples">
<Foo>1.234</Foo>
<Bar>A bunch of information</Bar>
</MySettings>
</configuration>
Related examples in the same category