From b2ad000e07e1c87d3561b5aa94fdc88c779872f0 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期二, 18 二月 2025 22:34:54 +0800
Subject: [PATCH] 1

---
 项目代码/WMS/WIDESEA_WMSServer/WIDESEA_Core/Helper/AppSettings.cs |   89 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 89 insertions(+), 0 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Core/Helper/AppSettings.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Core/Helper/AppSettings.cs"
new file mode 100644
index 0000000..1245695
--- /dev/null
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Core/Helper/AppSettings.cs"
@@ -0,0 +1,89 @@
+锘縰sing Microsoft.Extensions.Configuration.Json;
+using Microsoft.Extensions.Configuration;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WIDESEA_Core.Helper
+{
+    /// <summary>
+    /// appsettings.json鎿嶄綔绫�
+    /// </summary>
+    public class AppSettings
+    {
+        public static IConfiguration Configuration { get; set; }
+        static string contentPath { get; set; }
+
+        public AppSettings(string contentPath)
+        {
+            string Path = "appsettings.json";
+
+            //濡傛灉浣犳妸閰嶇疆鏂囦欢 鏄� 鏍规嵁鐜鍙橀噺鏉ュ垎寮�浜嗭紝鍙互杩欐牱鍐�
+            //Path = $"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")}.json";
+
+            Configuration = new ConfigurationBuilder()
+               .SetBasePath(contentPath)
+               .Add(new JsonConfigurationSource { Path = Path, Optional = false, ReloadOnChange = true })//杩欐牱鐨勮瘽锛屽彲浠ョ洿鎺ヨ鐩綍閲岀殑json鏂囦欢锛岃�屼笉鏄� bin 鏂囦欢澶逛笅鐨勶紝鎵�浠ヤ笉鐢ㄤ慨鏀瑰鍒跺睘鎬�
+               .Build();
+        }
+
+        public AppSettings(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 List<T>();
+            // 寮曠敤 Microsoft.Extensions.Configuration.Binder 鍖�
+            Configuration.Bind(string.Join(":", sections), list);
+            return list;
+        }
+
+
+        /// <summary>
+        /// 鏍规嵁璺緞  configuration["App:Name"];
+        /// </summary>
+        /// <param name="sectionsPath"></param>
+        /// <returns></returns>
+        public static string GetValue(string sectionsPath)
+        {
+            try
+            {
+                return Configuration[sectionsPath];
+            }
+            catch (Exception) { }
+
+            return "";
+
+        }
+    }
+}

--
Gitblit v1.9.3