Last change
on this file since 17395 was
17394,
checked in by dpiringe, 4 years ago
|
#3026:
- deleted: ConvertableAttribute, DummyConverter, ObjectExtensions
- renamed: CustomJsonWriter -> SingleLineArrayJsonWriter, JCInstantiator -> JsonTemplateInstantiator
- added: JsonItemConverterFactory, UnsupportedJsonItem
- IJsonItemConverter:
- added two new properties: Priority and ConvertableType -> because converters are automatically collected by plugin infrastructure now
- Extract, Inject references a root converter now -> typically an instance of JsonItemConverter -> to prevent cycles
- JsonItemConverter:
- now implements the interface IJsonItemConverter
- is now a dynamic class
- is only instantiable with an factory (JsonItemConverterFactory)
- still has the old (but now public) static methods Extract and Inject (without ref param IJsonItemConverter root) -> creates instance with factory and calls methods of instance
- removed register and unregister methods, because the factory collects all converters automatically now (on first call of Create)
- has cycle detection for Extract and Inject
- renamed method Get to GetConverter
|
File size:
1.4 KB
|
Rev | Line | |
---|
[17287] | 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 ValueLookupParameterConverter : ParameterBaseConverter {
|
---|
[17394] | 10 | public override int Priority => 4;
|
---|
| 11 | public override Type ConvertableType => typeof(IValueLookupParameter);
|
---|
| 12 |
|
---|
| 13 | public override void Populate(IParameter value, JsonItem item, IJsonItemConverter root) {
|
---|
| 14 | IValueLookupParameter param = value as IValueLookupParameter;
|
---|
| 15 |
|
---|
| 16 | item.Name = value.Name;
|
---|
| 17 | item.ActualName = param.ActualName;
|
---|
| 18 |
|
---|
[17342] | 19 | object actualValue = null;
|
---|
[17353] | 20 | IEnumerable<object> actualRange = null;
|
---|
[17342] | 21 | if(param.Value != null) {
|
---|
[17394] | 22 | JsonItem tmp = root.Extract(param.Value, root);
|
---|
| 23 | tmp.Parent = item;
|
---|
[17342] | 24 | actualValue = tmp.Value;
|
---|
| 25 | actualRange = tmp.Range;
|
---|
[17379] | 26 | } else {
|
---|
| 27 | actualRange = new object[] { GetMinValue(param.DataType), GetMaxValue(param.DataType) };
|
---|
[17342] | 28 | }
|
---|
[17394] | 29 | item.Value = actualValue;
|
---|
| 30 | item.Range = actualRange;
|
---|
[17287] | 31 | }
|
---|
| 32 |
|
---|
[17394] | 33 | public override void InjectData(IParameter parameter, JsonItem data, IJsonItemConverter root) {
|
---|
| 34 | IValueLookupParameter param = parameter as IValueLookupParameter;
|
---|
[17342] | 35 | param.ActualName = CastValue<string>(data.ActualName);
|
---|
| 36 | if (param.Value != null)
|
---|
[17394] | 37 | root.Inject(param.Value, data, root);
|
---|
[17287] | 38 | }
|
---|
| 39 | }
|
---|
| 40 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.