Created
December 9, 2014 08:50
-
-
Save larvata/f8935bfe32f703f333ef to your computer and use it in GitHub Desktop.
Common ConfigurationManager for app.config and web.config
This file contains 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
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