Last change
on this file since 17399 was
17394,
checked in by dpiringe, 5 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.1 KB
|
Rev | Line | |
---|
[17263] | 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 |
|
---|
[17284] | 8 | namespace HeuristicLab.JsonInterface {
|
---|
[17281] | 9 | public class ValueParameterConverter : ParameterBaseConverter {
|
---|
[17394] | 10 | public override int Priority => 2;
|
---|
| 11 | public override Type ConvertableType => typeof(IValueParameter);
|
---|
[17263] | 12 |
|
---|
[17394] | 13 | public override void InjectData(IParameter parameter, JsonItem data, IJsonItemConverter root) {
|
---|
[17342] | 14 | if (parameter.ActualValue == null && data.Value != null)
|
---|
| 15 | parameter.ActualValue = Instantiate(parameter.DataType);
|
---|
[17394] | 16 | root.Inject(parameter.ActualValue, data, root);
|
---|
[17342] | 17 | }
|
---|
[17263] | 18 |
|
---|
[17394] | 19 | public override void Populate(IParameter value, JsonItem item, IJsonItemConverter root) {
|
---|
| 20 | item.Name = value.Name;
|
---|
[17374] | 21 | if (value.ActualValue != null) {
|
---|
[17394] | 22 | JsonItem tmp = root.Extract(value.ActualValue, root);
|
---|
[17374] | 23 | if(tmp.Name == "[OverridableParamName]") {
|
---|
| 24 | tmp.Name = value.Name;
|
---|
[17394] | 25 | JsonItem.Merge(item, tmp);
|
---|
[17374] | 26 | }
|
---|
| 27 | else
|
---|
[17394] | 28 | item.AddChilds(tmp);
|
---|
[17374] | 29 | }
|
---|
[17266] | 30 | }
|
---|
[17263] | 31 | }
|
---|
| 32 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.