Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.