using System; using System.Configuration; namespace Quanjiang.DigitalScholl.SendSms { internal static class ConfigManager { private static readonly bool Error; private static readonly Configuration AppConfig; static ConfigManager() { var dllPath =$"{AppDomain.CurrentDomain.RelativeSearchPath ?? AppDomain.CurrentDomain.BaseDirectory}\\Quanjiang.DigitalScholl.SendSms.dll"; try { AppConfig = ConfigurationManager.OpenExeConfiguration(dllPath); } catch (ConfigurationErrorsException) { Error = true; } } public static KeyValueConfigurationCollection AppSettings { get { if (Error) return null; return AppConfig.AppSettings.Settings; } } public static ConnectionStringSettingsCollection ConnectionStrings { get { if (Error) return null; return AppConfig.ConnectionStrings.ConnectionStrings; } } public static T GetSection(string name) where T : ConfigurationSection { if (Error) return null; return AppConfig.GetSection(name) as T; } } }