Last change
on this file since 17712 was
17473,
checked in by dpiringe, 5 years ago
|
#3026:
- refactored inheritance structure of json items, now the default JsonItem is an abstract class without properties Value and Range -> splitted up into new interfaces
- updated view models for new json item structure
- updated SingleLineArrayJsonWriter
|
File size:
1.3 KB
|
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 |
|
---|
8 | namespace HeuristicLab.JsonInterface {
|
---|
9 | public class ParameterizedItemConverter : BaseConverter {
|
---|
10 | public override int Priority => 2;
|
---|
11 | public override Type ConvertableType => typeof(IParameterizedItem);
|
---|
12 |
|
---|
13 | public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) {
|
---|
14 | IParameterizedItem pItem = item as IParameterizedItem;
|
---|
15 |
|
---|
16 | if(data.Children != null) {
|
---|
17 | foreach (var sp in data.Children)
|
---|
18 | if (pItem.Parameters.TryGetValue(sp.Name, out IParameter param) && param != null)
|
---|
19 | root.Inject(param, sp, root);
|
---|
20 | }
|
---|
21 | }
|
---|
22 |
|
---|
23 | public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
|
---|
24 | var parameterizedItem = value as IParameterizedItem;
|
---|
25 |
|
---|
26 | IJsonItem item = new EmptyJsonItem() {
|
---|
27 | Name = value.ItemName,
|
---|
28 | Description = value.ItemDescription
|
---|
29 | };
|
---|
30 |
|
---|
31 | foreach (var param in parameterizedItem.Parameters) {
|
---|
32 | if (!param.Hidden) {
|
---|
33 | IJsonItem tmp = root.Extract(param, root);
|
---|
34 | if (!(tmp is UnsupportedJsonItem))
|
---|
35 | item.AddChildren(tmp);
|
---|
36 | }
|
---|
37 | }
|
---|
38 |
|
---|
39 | return item;
|
---|
40 | }
|
---|
41 | }
|
---|
42 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.