diff --git a/Pilz.Configuration/SettingsValueOption.cs b/Pilz.Configuration/SettingsValueOption.cs index 9620193..d3f96ed 100644 --- a/Pilz.Configuration/SettingsValueOption.cs +++ b/Pilz.Configuration/SettingsValueOption.cs @@ -1,4 +1,5 @@ using Newtonsoft.Json; +using System; namespace Pilz.Configuration; @@ -17,7 +18,7 @@ public class SettingsValueOption : ISettingsValueOptionValueAccessor where T public SettingsValueOption(T value) { - this.value = DefaultValue = value; + DefaultValue = value; } public virtual T Value @@ -34,7 +35,13 @@ public class SettingsValueOption : ISettingsValueOptionValueAccessor where T object ISettingsValueOptionValueAccessor.ValueRaw { get => value; - set => this.value = (T?)(T)value; + set + { + if (value is not null) + this.value = Convert.ChangeType(value, typeof(T)) as T?; + else + this.value = null; + } } public virtual void Reset()