Automates the process of tying config values back to strong-typed accessors.
Also enforces configuration value naming guidelines of "Fully.Qualified.Namespace.IndividualValue"

The tricky part is that the base class takes the inheritor as a generic argument to enable reflection.

A sample implementation of this class:
namespace Fully.Qualified.Namespace 
	public class Config : AutoConfig<Config>
		static Config() { Init(); } // this is critical

		public static int IndividualValue { get; private set; }

		public static int ValueWithNoDefault { get; private set; }
		public static int UpdateableValueWithNoDefault { get; set; }
		public static string ManuallyConfiguredProperty { get; set; }

Implementors of this AutoConfig class expect the following in the config file:
	<section name="Fully.Qualified.Namespace" type="System.Configuration.NameValueSectionHandler" />
	<add key="IndividualValue" value="8096" />

// This will also work, and these values override the section if both are provided:
	<add key="Fully.Qualified.Namespace.IndividualValue" value="65535" /> 

Last edited Jul 13, 2011 at 11:33 PM by InfiniteGeek, version 4


No comments yet.