AppSeting.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Configuration;
  4. using System.Linq;
  5. using System.Text;
  6. namespace cuidian.Common
  7. {
  8. public class AppSeting
  9. {
  10. private static AppSeting __app = new AppSeting();
  11. private AppSeting()
  12. { }
  13. public static AppSeting Instance
  14. {
  15. get { return __app; }
  16. }
  17. public string GetConnectstr(string key)
  18. {
  19. if (ConfigurationManager.ConnectionStrings[key] == null)
  20. {
  21. throw new Exception("配置文件中没有连接字串" + key);
  22. }
  23. return ConfigurationManager.ConnectionStrings[key].ToString();
  24. }
  25. public string GetValue(string key)
  26. {
  27. List<string> list = new List<string>();
  28. //list = (List<string>)ConfigurationManager.AppSettings.Keys.Cast<string>();
  29. if (ConfigurationManager.AppSettings.AllKeys.ToList().Contains(key))
  30. {
  31. return ConfigurationManager.AppSettings[key].ToString();
  32. }
  33. else
  34. {
  35. return string.Empty;
  36. }
  37. }
  38. }
  39. }