Created
February 12, 2014 14:56
-
-
Save csharpforevermore/8956976 to your computer and use it in GitHub Desktop.
Get a strongly-typed appsetting value
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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