Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 18183 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
Line 
1using System;
2using Newtonsoft.Json.Linq;
3using HEAL.Attic;
4
5namespace HeuristicLab.JsonInterface {
6  [StorableType("29139288-7ABB-4391-926E-5975CF38141E")]
7  public abstract class ValueJsonItem : JsonItem, IValueJsonItem {
8    public object Value { get; set; }
9
10    public override void SetJObject(JObject jObject) {
11      Value = jObject[nameof(IValueJsonItem.Value)]?.ToObject<object>();
12    }
13
14    public ValueJsonItem() { }
15
16    [StorableConstructor]
17    protected ValueJsonItem(StorableConstructorFlag _) : base(_) {
18    }
19
20  }
21
22  [StorableType("86085358-50D6-4486-9265-F6CEA8C8FA19")]
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
39    public override void SetJObject(JObject jObject) {
40      if (jObject[nameof(IValueJsonItem<T>.Value)] != null)
41        Value = jObject[nameof(IValueJsonItem<T>.Value)].ToObject<T>();
42    }
43
44    public ValueJsonItem() { }
45
46    [StorableConstructor]
47    protected ValueJsonItem(StorableConstructorFlag _) : base(_) { }
48  }
49}
Note: See TracBrowser for help on using the repository browser.