
Extend the Application Configuration File #48
Chapter 6, Speed Hacks
|
191
HACK
get{return this._server;}
}
public String Username
{
get{return this._username;}
}
public int Timeout
{
get{return this._timeout;}
}
internal static DatabaseSettingsConfig Create(
XmlElement configElement)
{
String server = ((String)(
DatabaseSettingsSectionHandler.GetValue(
configElement, "server", typeof(String), null)));
String username = ((String)(
DatabaseSettingsSectionHandler.GetValue(
configElement, "username",
typeof(String), null)));
int timeout = ((int )(
DatabaseSettingsSectionHandler.GetValue(
configElement, "timeout", typeof(int ), " 60")));
return new DatabaseSettingsConfig(
server, username, timeout);
}
}
}
Using the Code
To use this configuration section in your configuration file, you need to
declare your custom section in the
configSections section of the configura-
tion file for your application:
<configSections>
<section name="DatabaseSettings"
type="ConfigBuilderExample.DatabaseSettingsSectionHandler" />
</configSections>
ConfigBuilderExample is the name of my namespace in this example. Next,
you need to actually add your configuration section to the application con-
figuration file:
<configuration>
<DatabaseSettings server="localhost"
username="notsa" timeout="55" />
</configuration>