Skip to content

Instantly share code, notes, and snippets.

@fredgdaley2
Created February 22, 2017 01:54
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 fredgdaley2/9f6ea3822a86bac3b0ddf694f88c520c to your computer and use it in GitHub Desktop.
Save fredgdaley2/9f6ea3822a86bac3b0ddf694f88c520c to your computer and use it in GitHub Desktop.
Retrieve application settings
//Credit goes to this blog post https://dotnettips.wordpress.com/2013/03/07/retrieving-application-settings/
//USAGE: int serverPort = GetAppSetting<int>("server_port");
public static T GetAppSetting<T>(string key)
{
if (ConfigurationManager.AppSettings.AllKeys.Contains(key))
{
return (T)System.Convert.ChangeType(ConfigurationManager.AppSettings[key],
typeof(T), CultureInfo.InvariantCulture);
}
else
{
return default(T);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment