source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/ValueTypeMatrixConverter.cs @ 17281

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

#3026: renamed Transformers -> ...Transformer to ...Converter, ITypeTransformer to IJsonItemConverter, Transformer to JsonItemConverter

File size: 977 bytes
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6using Newtonsoft.Json.Linq;
7using HeuristicLab.Data;
8using HeuristicLab.Core;
9
10namespace HeuristicLab.Manufacture {
11  public class ValueTypeMatrixConverter<MatrixType, T> : BaseConverter
12    where MatrixType : ValueTypeMatrix<T>
13    where T : struct
14  {
15    public override void InjectData(IItem item, Component data) =>
16      CopyMatrixData(item.Cast<MatrixType>(), CastValue<T[,]>(data.Default));
17
18    public override Component ExtractData(IItem value) =>
19      new Component() {
20        Default = value.Cast<MatrixType>().CloneAsMatrix()
21      };
22
23    #region Helper
24    private void CopyMatrixData(MatrixType matrix, T[,] data) {
25      for (int x = 0; x < data.GetLength(0); ++x) {
26        for (int y = 0; y < data.GetLength(1); ++y) {
27          matrix[x, y] = data[x, y];
28        }
29      }
30    }
31    #endregion
32  }
33}
Note: See TracBrowser for help on using the repository browser.