Skip to content

Instantly share code, notes, and snippets.

@fdeitelhoff
Created February 20, 2013 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fdeitelhoff/4997012 to your computer and use it in GitHub Desktop.
Save fdeitelhoff/4997012 to your computer and use it in GitHub Desktop.
Extension method for the generic access to application settings.
public static T AppSetting<T>(this string key)
{
var value = default(T);
if (ConfigurationManager.AppSettings[key] != null)
{
var converter = TypeDescriptor.GetConverter(typeof (T));
value = (T)converter.ConvertFrom(ConfigurationManager.AppSettings[key]);
}
return value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment