Skip to content

Instantly share code, notes, and snippets.

@larvata
Created December 9, 2014 08:50
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 larvata/f8935bfe32f703f333ef to your computer and use it in GitHub Desktop.
Save larvata/f8935bfe32f703f333ef to your computer and use it in GitHub Desktop.
Common ConfigurationManager for app.config and web.config
using System.Collections.Specialized;
using System.Configuration;
using System.Reflection;
using System.Web.Configuration;
namespace TinyMess.Common
{
internal static class ConfigurationManagerWrapper
{
private static bool IsAspDotNet { get; set; }
static ConfigurationManagerWrapper()
{
IsAspDotNet = (Assembly.GetEntryAssembly() == null);
}
public static NameValueCollection AppSettings
{
get
{
return IsAspDotNet
? WebConfigurationManager.AppSettings
: ConfigurationManager.AppSettings;
}
}
public static ConnectionStringSettingsCollection ConnectionStrings
{
get
{
return IsAspDotNet
? WebConfigurationManager.ConnectionStrings
: ConfigurationManager.ConnectionStrings;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment