Config.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using Newtonsoft.Json;
  2. using Newtonsoft.Json.Linq;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Dynamic;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Web;
  9. /// <summary>
  10. /// Config 的摘要说明
  11. /// </summary>
  12. public static class Config
  13. {
  14. private static bool noCache = true;
  15. private static JObject BuildItems()
  16. {
  17. var json = File.ReadAllText(HttpContext.Current.Server.MapPath("config.json"));
  18. return JObject.Parse(json);
  19. }
  20. public static JObject Items
  21. {
  22. get
  23. {
  24. if (noCache || _Items == null)
  25. {
  26. _Items = BuildItems();
  27. }
  28. return _Items;
  29. }
  30. }
  31. private static JObject _Items;
  32. public static T GetValue<T>(string key)
  33. {
  34. return Items[key].Value<T>();
  35. }
  36. public static String[] GetStringList(string key)
  37. {
  38. return Items[key].Select(x => x.Value<String>()).ToArray();
  39. }
  40. public static String GetString(string key)
  41. {
  42. return GetValue<String>(key);
  43. }
  44. public static int GetInt(string key)
  45. {
  46. return GetValue<int>(key);
  47. }
  48. }