Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 17284 was 17284, checked in by dpiringe, 5 years ago

#3026: renamed namespace and project from HeuristicLab.Manufacture to HeuristicLab.JsonInterface

File size: 882 bytes
RevLine 
[17263]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
[17284]10namespace HeuristicLab.JsonInterface {
[17281]11  public class ValueTypeArrayConverter<ArrayType, T> : BaseConverter
[17263]12    where ArrayType : ValueTypeArray<T>
13    where T : struct
14  {
[17283]15    public override void InjectData(IItem item, JsonItem data) =>
[17266]16      CopyArrayData(item.Cast<ArrayType>(), CastValue<T[]>(data.Default));
[17263]17
[17283]18    public override JsonItem ExtractData(IItem value) =>
19      new JsonItem() {
[17266]20        Default = value.Cast<ArrayType>().CloneAsArray()
21      };
22
23    #region Helper
24    private void CopyArrayData(ArrayType array, T[] data) {
25      for (int i = 0; i < data.Length; ++i) {
26        array[i] = data[i];
[17263]27      }
28    }
[17266]29    #endregion
[17263]30  }
31}
Note: See TracBrowser for help on using the repository browser.