From ad15422700fee94cb04f9b7e32ca4e132e9484b0 Mon Sep 17 00:00:00 2001 From: Jack <3486688394@qq.com> Date: Tue, 21 Jan 2025 19:23:47 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E9=A1=B9=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JackCraft.Config/Config.cs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/JackCraft.Config/Config.cs b/JackCraft.Config/Config.cs index 6844c71..d65928b 100644 --- a/JackCraft.Config/Config.cs +++ b/JackCraft.Config/Config.cs @@ -106,4 +106,30 @@ public class Config var json = JsonConvert.SerializeObject(_configData, Formatting.Indented); File.WriteAllText(_configFile.FullName, json); } + + public void Delete(string key) + { + LoadConfigData(); + var keys = key.Split('.'); + var currentData = _configData; + + for (var i = 0; i < keys.Length - 1; i++) + { + var currentKey = keys[i]; + + if (!currentData.TryGetValue(currentKey, out var value)) return; + + if (value is JObject jObject) + currentData[currentKey] = + jObject.ToObject>() ?? new Dictionary(); + + currentData = (Dictionary)currentData[currentKey]; + } + + var finalKey = keys[^1]; + currentData.Remove(finalKey); + + var json = JsonConvert.SerializeObject(_configData, Formatting.Indented); + File.WriteAllText(_configFile.FullName, json); + } } \ No newline at end of file