优化代码,封装json读取方法
This commit is contained in:
parent
f0df39d658
commit
d3f7d2e07c
@ -48,10 +48,7 @@ namespace AntdUIDemo
|
||||
private void LoadAppConfig()
|
||||
{
|
||||
// 读取 appsettings.json 文件
|
||||
var configFilePath = "appsettings.json";
|
||||
var json = File.ReadAllText(configFilePath);
|
||||
var jsonObj = JObject.Parse(json);
|
||||
var appSettings = jsonObj["AppSettings"];
|
||||
var appSettings = ConfigurationHelper.GetAppSettings();
|
||||
|
||||
// 加载色彩模式
|
||||
var value = appSettings["ColorMode"]?.ToString();
|
||||
@ -88,10 +85,7 @@ namespace AntdUIDemo
|
||||
private void Button_color_Click(object sender, EventArgs e)
|
||||
{
|
||||
// 读取 appsettings.json 文件
|
||||
var configFilePath = "appsettings.json";
|
||||
var json = File.ReadAllText(configFilePath);
|
||||
var jsonObj = JObject.Parse(json);
|
||||
var appSettings = jsonObj["AppSettings"];
|
||||
var appSettings = ConfigurationHelper.GetAppSettings();
|
||||
var value = appSettings["ColorMode"]?.ToString();
|
||||
if (value == "Auto")
|
||||
{
|
||||
@ -314,6 +308,7 @@ namespace AntdUIDemo
|
||||
}
|
||||
if (control != null)
|
||||
{
|
||||
//容器添加控件,需要调整dpi
|
||||
AutoDpi(control);
|
||||
panel_content.Controls.Add(control);
|
||||
}
|
||||
|
||||
@ -9,7 +9,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace AntdUIDemo.Utils
|
||||
{
|
||||
public static class AppSetting
|
||||
public class AppSetting
|
||||
{
|
||||
private static readonly string configFilePath = "appsettings.json";
|
||||
|
||||
|
||||
25
Utils/ConfigurationHelper.cs
Normal file
25
Utils/ConfigurationHelper.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AntdUIDemo.Utils
|
||||
{
|
||||
public class ConfigurationHelper
|
||||
{
|
||||
public static JObject GetAppSettings(string configFilePath = "appsettings.json")
|
||||
{
|
||||
// Read the JSON file
|
||||
var json = File.ReadAllText(configFilePath);
|
||||
|
||||
// Parse the JSON object
|
||||
var jsonObj = JObject.Parse(json);
|
||||
|
||||
// Return the "AppSettings" section
|
||||
return (JObject)jsonObj["AppSettings"];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace AntdUIDemo.Utils
|
||||
{
|
||||
public static class LoggerHelper
|
||||
public class LoggerHelper
|
||||
{
|
||||
public static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
}
|
||||
|
||||
@ -9,7 +9,7 @@ using Microsoft.Win32;
|
||||
|
||||
namespace AntdUIDemo.Utils
|
||||
{
|
||||
public static class ThemeHelper
|
||||
public class ThemeHelper
|
||||
{
|
||||
public static bool IsLightMode()
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user