Removed the key-value pair methods for settings and replaced them helpers for JSON serialization and deserialization. This is because the key-value pair is pretty limited, easy to break and wasn't even being used anyway, JSON is far superior for storing a dictionary.

This commit is contained in:
barelyprofessional
2024-09-01 20:22:28 +08:00
parent 2906481b27
commit b3dc9a23e4
+5 -5
View File
@@ -1,3 +1,4 @@
using System.Text.Json;
using NLog; using NLog;
namespace KfChatDotNetBot.Settings; namespace KfChatDotNetBot.Settings;
@@ -10,15 +11,14 @@ public static class Utils
return settingValue.Value.Split(separator).ToList(); return settingValue.Value.Split(separator).ToList();
} }
public static Dictionary<string, T> ToKeyValuePairs<T>(this SettingValue settingValue, char delimiter = ',', public static T? JsonDeserialize<T>(this SettingValue settingValue)
char separator = '=')
{ {
if (settingValue.Value == null) if (settingValue.Value == null)
{ {
return new Dictionary<string, T>(); return default;
} }
return settingValue.Value.Split(delimiter).ToDictionary(kv => kv.Split(separator)[0],
kv => ValueToType<T>(kv.Split(separator)[1])); return JsonSerializer.Deserialize<T>(settingValue.Value) ?? default(T);
} }
public static bool ToBoolean(this SettingValue settingValue) public static bool ToBoolean(this SettingValue settingValue)