mirror of
https://github.com/barelyprofessional/KfChatDotNet.git
synced 2026-04-30 03:22:04 -04:00
- Methods are now suffixed async - Extension methods moved to the actual class and class renamed from SettingValue to Setting - "Helpers" renamed to "SettingsProvider" - Removed the ghetto CSV list method. Only setting using it was Pusher Channels which was orphaned by the new Kick channel feature. The call to ToList in the Chips.gg integration was incorrect and just proves lists should be consistently based around JSON objects instead of randomly string splitting
31 lines
775 B
C#
31 lines
775 B
C#
using System.Text.Json;
|
|
using KfChatDotNetBot.Models.DbModels;
|
|
|
|
namespace KfChatDotNetBot.Settings;
|
|
|
|
public class Setting(string? value, SettingDbModel dbEntry, bool cached)
|
|
{
|
|
public string? Value { get; set; } = value;
|
|
public SettingDbModel DbEntry { get; set; } = dbEntry;
|
|
public bool Cached { get; set; } = cached;
|
|
|
|
public T? JsonDeserialize<T>()
|
|
{
|
|
if (Value == null)
|
|
{
|
|
return default;
|
|
}
|
|
|
|
return JsonSerializer.Deserialize<T>(Value) ?? default(T);
|
|
}
|
|
|
|
public bool ToBoolean()
|
|
{
|
|
return Value is not (null or "null") && Value.Equals("true", StringComparison.CurrentCultureIgnoreCase);
|
|
}
|
|
|
|
public T ToType<T>()
|
|
{
|
|
return (T)Convert.ChangeType(Value, typeof(T))!;
|
|
}
|
|
} |