Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueTypeArrayConverter.cs @ 17374

Last change on this file since 17374 was 17374, checked in by dpiringe, 4 years ago

#3026:

  • extended the BaseConverter class to set the type of the extracted value and removed the assignment of type in all other converters
  • fixed a bug in ConfigurableConverter -> now it correctly iterates through all items from an IEnumerable and calls the extract callback
  • MultiCheckedOperatorConverter:
    • deleted unnecessary code line
    • now adds operators to parameters (instead of operator list, because the operator list will get removed in a future commit)
    • does not set the path of its added items anymore
  • ParameterBaseConverter removed unnecessary code lines
  • deleted ParameterBaseConverter
  • reimplemented StorableConverter to test it again (still not really useable, because it bloats the template massively)
  • fixed a pathing bug in ValueParameterConverter (extended ValueRangeConverter, ValueTypeArrayConverter, ValueTypeMatrixConverter, ValueTypeValueConverter to archive this)
  • JCGenerator now only writes a single array with parameters (only FreeParameters) and saves a .hl File to test a new type of implementation of the whole JsonInterface
  • fixed a bug in JsonItem -> now it replaces the name in path of the item (not the whole path as it was before)
File size: 1.0 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6using HeuristicLab.Core;
7using HeuristicLab.Data;
8using Newtonsoft.Json.Linq;
9
10namespace HeuristicLab.JsonInterface {
11  public class ValueTypeArrayConverter<ArrayType, T> : BaseConverter
12    where ArrayType : ValueTypeArray<T>
13    where T : struct
14  {
15    public override void InjectData(IItem item, JsonItem data) =>
16      CopyArrayData(item.Cast<ArrayType>(), CastValue<T[]>(data.Value));
17
18    public override JsonItem ExtractData(IItem value) =>
19      new JsonItem() {
20        Name = "[OverridableParamName]",
21        Value = value.Cast<ArrayType>().CloneAsArray()
22      };
23
24    #region Helper
25    private void CopyArrayData(ArrayType array, T[] data) {
26      var colInfo = array.GetType().GetProperty("Length");
27      colInfo.SetValue(array, data.Length);
28      for (int i = 0; i < data.Length; ++i) {
29        array[i] = data[i];
30      }
31    }
32    #endregion
33  }
34}
Note: See TracBrowser for help on using the repository browser.