
188
|
Chapter 6, Speed Hacks
#48 Extend the Application Configuration File
HACK
In this file, I am creating a single element called DatabaseSettings that has
three different attributes; the first two are strings and the last is an integer.
You can also define default values for attributes in the template file. In this
example, suppose that I want to set a default value for the
timeout attribute
parameter. I can do this by simply adding a colon after the type and then
specifying my default value. My template file would now look like this:
<configuration>
<DatabaseSettings server="string"
username="string" timeout="int: 60" />
</configuration>
By declaring a default value, the attribute is no longer required. If the
timeout attribute is omitted in the configuration section for this application
config file, the code will simply assume the value is 60. (When declaring
default values for strings, you must use
[Empty] to signify an empty string.)
You can also specify the number of times a section can appear, create section
groups, and specify comments to be included in the generated code. Explana-
tions of these features can all be found in ConfigBuilder’s documentation.
Running the ConfigBuilder
To execute the template file and generate the code, you need to specify Con-
figBuilder as the custom tool for this file. This is done by simply entering
ConfigBuilder into the Custom Tool field in the .XML file’s