.Net 6 读取Appsetting的值的复制类


    public class AppSettings
    {
        static IConfiguration Configuration { get; set; }
        static string ContentPath { get; set; }

        public AppSettings()
        {
            string path = "appsettings.json";
            Configuration = new ConfigurationBuilder().SetBasePath(ContentPath).Add(new JsonConfigurationSource { Path = path, Optional = false, ReloadOnChange = true }).Build();
        }
        public AppSettings(IConfiguration configuration)
        {
            Configuration = configuration;
        }
        public static string app(params string[] sections)
        {
            try
            {
                if (sections.Any())
                {
                    return Configuration[string.Join(":", sections)];
                }
            }
            catch (Exception ex)
            {

            }
            return "";
        }

        public static List<T>app<T>(params string[] sections)
        {
            List<T> list=new List<T>();
            Configuration.Bind(string.Join(":", sections), list);
            return list;
        }


    }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM