Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JsonItems/ValueJsonItem.cs @ 18055

Last change on this file since 18055 was 18055, checked in by dpiringe, 3 years ago

#3026

  • added StorableTypeAttribute and StorableConstructorAttribute to all JsonItems
  • added a new JsonItem ListJsonItem + Interfaces IListJsonItem
  • renamed SymRegPythonProcessor to RunCollectionSRSolutionPythonFormatter
  • removed Interface IResultCollectionProcessor -> using the interface IRunCollectionModifier now (has aleady implementations)
  • renamed all related variables/fields/properties with a connection to ResultCollectionProcessor
  • added new implementations for IRunCollectionModifier
File size: 1.3 KB
RevLine 
[17473]1using System;
2using Newtonsoft.Json.Linq;
[18055]3using HEAL.Attic;
[17473]4
5namespace HeuristicLab.JsonInterface {
[18055]6  [StorableType("29139288-7ABB-4391-926E-5975CF38141E")]
[17473]7  public abstract class ValueJsonItem : JsonItem, IValueJsonItem {
8    public object Value { get; set; }
9
[17477]10    public override void SetJObject(JObject jObject) {
[17473]11      Value = jObject[nameof(IValueJsonItem.Value)]?.ToObject<object>();
12    }
13
[18055]14    public ValueJsonItem() { }
15
16    [StorableConstructor]
17    protected ValueJsonItem(StorableConstructorFlag _) : base(_) {
18    }
19
[17473]20  }
21
[18055]22  [StorableType("86085358-50D6-4486-9265-F6CEA8C8FA19")]
[17473]23  public abstract class ValueJsonItem<T> : ValueJsonItem, IValueJsonItem<T> {
24    public new T Value {
25      get => ConvertObject(base.Value);
26      set => base.Value = value;
27    }
28
29    private T ConvertObject(object obj) {
30      if (obj is IConvertible)
31        return (T)Convert.ChangeType(obj, typeof(T));
32
33      if (obj is JToken token)
34        return token.ToObject<T>();
35
36      return (T)obj;
37    }
38
[17477]39    public override void SetJObject(JObject jObject) {
[18055]40      if (jObject[nameof(IValueJsonItem<T>.Value)] != null)
[17473]41        Value = jObject[nameof(IValueJsonItem<T>.Value)].ToObject<T>();
42    }
[18055]43
44    public ValueJsonItem() { }
45
46    [StorableConstructor]
47    protected ValueJsonItem(StorableConstructorFlag _) : base(_) { }
[17473]48  }
49}
Note: See TracBrowser for help on using the repository browser.