Last change
on this file since 17346 was
17346,
checked in by dpiringe, 5 years ago
|
#3026 fixed a bug in ValueTypeArrayConverter -> now it correctly resizes ValueTypeArray<T>
|
File size:
983 bytes
|
Line | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.Threading.Tasks;
|
---|
6 | using HeuristicLab.Core;
|
---|
7 | using HeuristicLab.Data;
|
---|
8 | using Newtonsoft.Json.Linq;
|
---|
9 |
|
---|
10 | namespace 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 | Value = value.Cast<ArrayType>().CloneAsArray()
|
---|
21 | };
|
---|
22 |
|
---|
23 | #region Helper
|
---|
24 | private void CopyArrayData(ArrayType array, T[] data) {
|
---|
25 | var colInfo = array.GetType().GetProperty("Length");
|
---|
26 | colInfo.SetValue(array, data.Length);
|
---|
27 | for (int i = 0; i < data.Length; ++i) {
|
---|
28 | array[i] = data[i];
|
---|
29 | }
|
---|
30 | }
|
---|
31 | #endregion
|
---|
32 | }
|
---|
33 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.