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