You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

50 lines
1.3 KiB

  1. using System;
  2. using System.Configuration;
  3. namespace Quanjiang.DigitalScholl.SendSms
  4. {
  5. internal static class ConfigManager
  6. {
  7. private static readonly bool Error;
  8. private static readonly Configuration AppConfig;
  9. static ConfigManager()
  10. {
  11. var dllPath =$"{AppDomain.CurrentDomain.RelativeSearchPath ?? AppDomain.CurrentDomain.BaseDirectory}\\Quanjiang.DigitalScholl.SendSms.dll";
  12. try
  13. {
  14. AppConfig = ConfigurationManager.OpenExeConfiguration(dllPath);
  15. }
  16. catch (ConfigurationErrorsException)
  17. {
  18. Error = true;
  19. }
  20. }
  21. public static KeyValueConfigurationCollection AppSettings
  22. {
  23. get
  24. {
  25. if (Error) return null;
  26. return AppConfig.AppSettings.Settings;
  27. }
  28. }
  29. public static ConnectionStringSettingsCollection ConnectionStrings
  30. {
  31. get
  32. {
  33. if (Error) return null;
  34. return AppConfig.ConnectionStrings.ConnectionStrings;
  35. }
  36. }
  37. public static T GetSection<T>(string name) where T : ConfigurationSection
  38. {
  39. if (Error) return null;
  40. return AppConfig.GetSection(name) as T;
  41. }
  42. }
  43. }