1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- using Microsoft.Extensions.Configuration.Json;
- namespace DataControlMod.Common
- {
- public class AppSettingsHelper
- {
- static IConfiguration? Configuration { get; set; }
- static string? ContentPath { get; set; }
- public AppSettingsHelper(IConfiguration configuration)
- {
- Configuration = configuration;
- }
- /// <summary>
- /// 封装要操作的字符
- /// </summary>
- /// <param name="sections">节点配置</param>
- /// <returns></returns>
- public static string App(params string[] sections)
- {
- try
- {
- if (sections.Any())
- {
- return Configuration[string.Join(":", sections)];
- }
- }
- catch (Exception)
- {
- }
- return "";
- }
- /// <summary>
- /// 递归获取配置信息数组
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="sections"></param>
- /// <returns></returns>
- public static List<T> App<T>(params string[] sections)
- {
- List<T> list = new();
- Configuration.Bind(string.Join(":", sections), list);
- return list;
- }
- }
- }
|