From 4bdb3389640a47cc88ae4bcc9c96d678c008c2b7 Mon Sep 17 00:00:00 2001 From: czz_y Date: Mon, 9 Sep 2024 09:10:56 +0800 Subject: [PATCH] =?UTF-8?q?json=E6=96=87=E4=BB=B6=E5=AD=98=E5=9C=A8?= =?UTF-8?q?=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MainWindow.cs | 3 ++- Utils/ConfigurationHelper.cs | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/MainWindow.cs b/MainWindow.cs index 7f0d5b8..7ff5e65 100644 --- a/MainWindow.cs +++ b/MainWindow.cs @@ -49,7 +49,7 @@ namespace AntdUIDemo { // 读取 appsettings.json 文件 var appSettings = ConfigurationHelper.GetAppSettings(); - + if (appSettings == null) return; // 加载色彩模式 var value = appSettings["ColorMode"]?.ToString(); if (value == "Auto") @@ -86,6 +86,7 @@ namespace AntdUIDemo { // 读取 appsettings.json 文件 var appSettings = ConfigurationHelper.GetAppSettings(); + if (appSettings == null) return; var value = appSettings["ColorMode"]?.ToString(); if (value == "Auto") { diff --git a/Utils/ConfigurationHelper.cs b/Utils/ConfigurationHelper.cs index 3a251cd..bd4e982 100644 --- a/Utils/ConfigurationHelper.cs +++ b/Utils/ConfigurationHelper.cs @@ -12,6 +12,10 @@ namespace AntdUIDemo.Utils { public static JObject GetAppSettings(string configFilePath = "appsettings.json") { + if (!File.Exists(configFilePath)) + { + return null; + } // Read the JSON file var json = File.ReadAllText(configFilePath);