Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/17/20 12:33:35 (4 years ago)
Author:
dpiringe
Message:

#3026:

  • refactored JsonTemplateInstantiator -> now returns a InstantiatorResult which contains the optimizer and an IEnumerable of IResultJsonItem
  • code cleanup in JCGenerator
  • relocated the serialization of json items into IJsonItem with method GenerateJObject (virtual base implementation in JsonItem)
    • this allows custom serialization for json items (example: ValueLookupJsonItem)
    • items of interface IIntervalRestrictedJsonItem have a custom implementation of GenerateJObject -> hides Minimum and Maximum if the values are the physically min/max of their type
  • code cleanup in BaseConverter
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Models/ValueLookupJsonItem.cs

    r17473 r17477  
    55using System.Threading.Tasks;
    66using Newtonsoft.Json;
     7using Newtonsoft.Json.Linq;
    78
    89namespace HeuristicLab.JsonInterface {
    910  public class ValueLookupJsonItem : LookupJsonItem, IValueLookupJsonItem {
    10     [JsonIgnore]
    11     public IJsonItem JsonItemReference { get; set; }
     11   
     12    public IJsonItem ActualValue { get; set; }
    1213
    1314    protected override bool Validate() {
    14       if (JsonItemReference == null) return true;
     15      if (ActualValue == null) return true;
    1516      IList<IJsonItem> faultyItems = new List<IJsonItem>();
    16       return JsonItemReference.GetValidator().Validate(ref faultyItems);
     17      return ActualValue.GetValidator().Validate(ref faultyItems);
     18    }
     19
     20    public override JObject GenerateJObject() {
     21      var obj = base.GenerateJObject();
     22      if(ActualValue != null) {
     23        var actualValue = ActualValue.GenerateJObject();
     24        obj.Add(nameof(IValueLookupJsonItem.ActualValue), actualValue);
     25      }
     26      return obj;
     27    }
     28
     29    public override IEnumerator<IJsonItem> GetEnumerator() {
     30      using (var it = base.GetEnumerator()) {
     31        while(it.MoveNext()) {
     32          yield return it.Current;
     33        }
     34      }
     35      if(ActualValue != null) {
     36        using (var it = ActualValue.GetEnumerator()) {
     37          while (it.MoveNext()) {
     38            yield return it.Current;
     39          }
     40        }
     41      }
    1742    }
    1843  }
Note: See TracChangeset for help on using the changeset viewer.