Tag Archives: Configuration

Using T4 to Create an AppSettings Wrapper, Part 2

Published on: Author: Michael

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

Published on: Author: Michael

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