Using T4 to Create an AppSettings Wrapper, Part 4

In the previous article we finished the basic appsettings template that allowed us to generate a strongly typed class from the settings in a configuration file.  We now want to expand the template to allow it to be customized depending upon the needs of the project, a later article.  Before we get there though it […]

Continue Reading...

Using T4 to Create an AppSettings Wrapper, Part 3

In the previous article we expanded the template to dynamically set the type and namespace names based upon the project the template is used in.  Now we are going to turn our focus to generating properties for each of the settings in the configuration file.  For this we’ll be adding more code to the class […]

Continue Reading...

Using T4 to Create an AppSettings Wrapper, Part 2

In the first article in this series we created a basic, static T4 template.  The template allowed us to replace standard boilerplate code for reading an app setting string setting = ConfigurationManager.AppSettings["someSetting"]; with strongly typed property references like this var myIntSetting = AppSettings.Default.IntValue; var myDoubleSettig = AppSettings.Default.DoubleValue; Here’s a summary of the requirements from the first article (slightly reordered). All settings defined in the […]

Continue Reading...

Using T4 to Create an AppSettings Wrapper, Part 1

AppSettings are settings stored in your configuration file under the <appSettings> element. Almost every application has them. Each setting consists of a name and value. To access such a setting in code you need only do this. string setting = ConfigurationManager.AppSettings["someSetting"]; There are a couple of problems with this approach. Quite a bit of boilerplate code to access […]

Continue Reading...

Strongly Typed Application Settings Using T4

We all know that the Settings infrastructure added to .NET a while back is the “correct” way to create strongly typed application settings in configuration files.  The problem with this approach though is that the entries generated in the config file aren’t pretty.  You have only limited control over the naming, there are lots of […]

Continue Reading...