json文件存在判断

This commit is contained in:
czz_y 2024-09-09 09:10:56 +08:00
parent d3f7d2e07c
commit 4bdb338964
2 changed files with 6 additions and 1 deletions

View File

@ -49,7 +49,7 @@ namespace AntdUIDemo
{ {
// 读取 appsettings.json 文件 // 读取 appsettings.json 文件
var appSettings = ConfigurationHelper.GetAppSettings(); var appSettings = ConfigurationHelper.GetAppSettings();
if (appSettings == null) return;
// 加载色彩模式 // 加载色彩模式
var value = appSettings["ColorMode"]?.ToString(); var value = appSettings["ColorMode"]?.ToString();
if (value == "Auto") if (value == "Auto")
@ -86,6 +86,7 @@ namespace AntdUIDemo
{ {
// 读取 appsettings.json 文件 // 读取 appsettings.json 文件
var appSettings = ConfigurationHelper.GetAppSettings(); var appSettings = ConfigurationHelper.GetAppSettings();
if (appSettings == null) return;
var value = appSettings["ColorMode"]?.ToString(); var value = appSettings["ColorMode"]?.ToString();
if (value == "Auto") if (value == "Auto")
{ {

View File

@ -12,6 +12,10 @@ namespace AntdUIDemo.Utils
{ {
public static JObject GetAppSettings(string configFilePath = "appsettings.json") public static JObject GetAppSettings(string configFilePath = "appsettings.json")
{ {
if (!File.Exists(configFilePath))
{
return null;
}
// Read the JSON file // Read the JSON file
var json = File.ReadAllText(configFilePath); var json = File.ReadAllText(configFilePath);