Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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