using System; using Newtonsoft.Json.Linq; namespace HeuristicLab.JsonInterface { public abstract class ValueJsonItem : JsonItem, IValueJsonItem { public object Value { get; set; } public override void SetJObject(JObject jObject) { Value = jObject[nameof(IValueJsonItem.Value)]?.ToObject(); } } public abstract class ValueJsonItem : ValueJsonItem, IValueJsonItem { public new T Value { get => ConvertObject(base.Value); set => base.Value = value; } private T ConvertObject(object obj) { if (obj is IConvertible) return (T)Convert.ChangeType(obj, typeof(T)); if (obj is JToken token) return token.ToObject(); return (T)obj; } public override void SetJObject(JObject jObject) { if(jObject[nameof(IValueJsonItem.Value)] != null) Value = jObject[nameof(IValueJsonItem.Value)].ToObject(); } } }