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.

44 lines
1.2 KiB

2 years ago
  1. using System;
  2. using System.Configuration;
  3. namespace EasyNet.Common
  4. {
  5. public class CommonUtils
  6. {
  7. /// <summary>
  8. /// 用於字串和枚舉類型的轉換
  9. /// </summary>
  10. /// <typeparam name="T"></typeparam>
  11. /// <param name="value"></param>
  12. /// <returns></returns>
  13. public static T EnumParse<T>(string value)
  14. {
  15. try
  16. {
  17. return (T)Enum.Parse(typeof(T), value);
  18. }
  19. catch
  20. {
  21. throw new Exception("傳入的值與枚舉值不匹配。");
  22. }
  23. }
  24. /// <summary>
  25. /// 根據傳入的Key獲取設定檔中的Value值
  26. /// </summary>
  27. /// <param name="Key"></param>
  28. /// <returns></returns>
  29. public static string GetConfigValueByKey(string Key)
  30. {
  31. return ConfigurationManager.AppSettings[Key];
  32. }
  33. public static Boolean IsNullOrEmpty(Object value)
  34. {
  35. if (value == null)
  36. return true;
  37. if (String.IsNullOrEmpty(value.ToString()))
  38. return true;
  39. return false;
  40. }
  41. }
  42. }