ConfigHelper.cs 838 B

12345678910111213141516171819202122232425262728293031
  1. using System.Configuration;
  2. namespace FCS.Common
  3. {
  4. /// <summary>
  5. /// 配置管理类
  6. /// </summary>
  7. public static class ConfigHelper
  8. {
  9. /// <summary>
  10. /// 获取指定返回类型的配置项值
  11. /// 如果类型不匹配则返回该返回类型默认值
  12. /// </summary>
  13. /// <typeparam name="T">指定返回类型</typeparam>
  14. /// <param name="key">配置项key</param>
  15. /// <returns></returns>
  16. public static T GetConfigValue<T>(string key)
  17. {
  18. try
  19. {
  20. object o = ConfigurationManager.AppSettings[key];
  21. if (o != null)
  22. {
  23. return CommonHelper.ChangeType<T>(o);
  24. }
  25. }
  26. catch { }
  27. return default(T);
  28. }
  29. }
  30. }