Last change
on this file since 18040 was
18040,
checked in by dpiringe, 3 years ago
|
#3026
- added some test cases for JsonInterface
- deleted the HeuristicLab namespace part in a lot of test classes (this caused a lot of compile errors)
- enhanced the OS path logic for absolute and relative path in JsonTemplateGenerator and JsonTemplateInstantiator
- fixed a bug in ValueParameterConverter -> the injection logic was not working correctly
- changed the folder determination in Main.cs for the HeadlessRun method
- added a new abstract type of JsonItem IntervalRestrictedJsonItem for JsonItems with a need of Minimum and Maximum bounds but without a specific value
- changed in RangedJsonItem the base class from IntervalRestrictedValueJsonItem to IntervalRestrictedJsonItem
|
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 ValueParameterConverter : BaseConverter {
|
---|
10 | public override int Priority => 2;
|
---|
11 |
|
---|
12 | public override bool CanConvertType(Type t) =>
|
---|
13 | t.GetInterfaces().Any(x => x == typeof(IValueParameter));
|
---|
14 |
|
---|
15 | public override void Inject(IItem value, IJsonItem data, IJsonItemConverter root) {
|
---|
16 | IParameter parameter = value as IParameter;
|
---|
17 |
|
---|
18 | if (!(data is EmptyJsonItem)) {
|
---|
19 | if (parameter.ActualValue == null)
|
---|
20 | parameter.ActualValue = Instantiate(parameter.DataType);
|
---|
21 | root.Inject(parameter.ActualValue, data, root);
|
---|
22 | }
|
---|
23 | }
|
---|
24 |
|
---|
25 | public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
|
---|
26 | IParameter parameter = value as IParameter;
|
---|
27 |
|
---|
28 | IJsonItem item = new EmptyJsonItem() {
|
---|
29 | Name = parameter.Name,
|
---|
30 | Description = parameter.Description
|
---|
31 | };
|
---|
32 |
|
---|
33 | if (parameter.ActualValue != null) {
|
---|
34 | IJsonItem tmp = root.Extract(parameter.ActualValue, root);
|
---|
35 | if (!(tmp is UnsupportedJsonItem)) {
|
---|
36 | tmp.Name = parameter.Name;
|
---|
37 | tmp.Description = parameter.Description;
|
---|
38 | item = tmp;
|
---|
39 | }
|
---|
40 | }
|
---|
41 | return item;
|
---|
42 | }
|
---|
43 | }
|
---|
44 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.