Skip to content

Instantly share code, notes, and snippets.

@csharpforevermore
Created February 12, 2014 14:56
Show Gist options
  • Save csharpforevermore/8956976 to your computer and use it in GitHub Desktop.
Save csharpforevermore/8956976 to your computer and use it in GitHub Desktop.
Get a strongly-typed appsetting value
public static T GetAppSetting<T>(string key, T defaultValue)
{
var reader = new AppSettingsReader();
try
{
return (T)reader.GetValue(key, typeof(T));
}
catch (InvalidOperationException)
{
return defaultValue;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment