.Net Core 读取 appsettings.json 类

  public class ConfigureServices
    {

        private static IConfiguration _config;

        public ConfigureServices(IConfiguration configuration)
        {
            _config = configuration;
        }

        /// 
        /// 读取指定节点的字符串
        /// 
        /// 
        /// 
        
        public static string ReadAppSettings(params string[] sessions)
        {
            try
            {
                if (sessions.Any()) return _config[string.Join(":", sessions)];
            }
            catch
            {
                return "";
            }
            return "";
        }

        /// 
        /// 读取实体信息
        /// 
        /// 
        /// 
        /// 
        public static List ReadAppSettings(params string[] session)
        {
            List list = new List();
            _config.Bind(string.Join(":", session), list);
            return list;
        }
  
    }

你可能感兴趣的:(c#,.NetCore,开发语言,c#)