mirror of
https://github.com/barelyprofessional/KfChatDotNet.git
synced 2026-05-14 18:12:43 -04:00
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:
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user