AppSettingsHelper.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using Microsoft.Extensions.Configuration.Json;
  2. namespace DataControlMod.Common
  3. {
  4. public class AppSettingsHelper
  5. {
  6. static IConfiguration? Configuration { get; set; }
  7. static string? ContentPath { get; set; }
  8. public AppSettingsHelper(IConfiguration configuration)
  9. {
  10. Configuration = configuration;
  11. }
  12. /// <summary>
  13. /// 封装要操作的字符
  14. /// </summary>
  15. /// <param name="sections">节点配置</param>
  16. /// <returns></returns>
  17. public static string App(params string[] sections)
  18. {
  19. try
  20. {
  21. if (sections.Any())
  22. {
  23. return Configuration[string.Join(":", sections)];
  24. }
  25. }
  26. catch (Exception)
  27. {
  28. }
  29. return "";
  30. }
  31. /// <summary>
  32. /// 递归获取配置信息数组
  33. /// </summary>
  34. /// <typeparam name="T"></typeparam>
  35. /// <param name="sections"></param>
  36. /// <returns></returns>
  37. public static List<T> App<T>(params string[] sections)
  38. {
  39. List<T> list = new();
  40. Configuration.Bind(string.Join(":", sections), list);
  41. return list;
  42. }
  43. }
  44. }