Skip to Main Content
Visual Studio Hacks
book

Visual Studio Hacks

by James Avery
March 2005
Intermediate to advanced content levelIntermediate to advanced
304 pages
19h 23m
English
O'Reilly Media, Inc.
Content preview from Visual Studio Hacks
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
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Microsoft Visual Studio 2015 Unleashed, Third Edition

Microsoft Visual Studio 2015 Unleashed, Third Edition

Mike Snell, Lars Powers
.Net Framework Essentials

.Net Framework Essentials

Thuan L. Thai, Hoang Lam
C# 5.0 Unleashed

C# 5.0 Unleashed

Bart De Smet
Programming .NET Security

Programming .NET Security

Adam Freeman, Allen Jones

Publisher Resources

ISBN: 0596008473Errata Page