Last change
on this file since 17828 was
17828,
checked in by dpiringe, 3 years ago
|
#3026
- removed the option to set the value for JsonItems via exporter
- reworked some base controls
- added new controls for JsonItem specific properties (e.g. ArrayResizable)
- deleted a lot of obsolet controls
- removed the Enable checkbox in the detail view of JsonItems
- exporter now clones the IOptimizer object
- added a check + message for unsupported exports
- list of JsonItems now includes unsupported JsonItems (disabled and marked with 'unsupported')
- refactored the converter type check
- now every converter has to specify its supported type(s)
|
File size:
1.2 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 | using HeuristicLab.Data;
|
---|
| 8 |
|
---|
[17284] | 9 | namespace HeuristicLab.JsonInterface {
|
---|
[17281] | 10 | public class EnumTypeConverter : BaseConverter {
|
---|
[17394] | 11 | public override int Priority => 1;
|
---|
| 12 | public override Type ConvertableType => typeof(EnumValue<>);
|
---|
| 13 |
|
---|
[17828] | 14 | public override bool CanConvertType(Type t) =>
|
---|
| 15 | typeof(EnumValue<>).IsAssignableFrom(t) ||
|
---|
| 16 | (t.IsGenericType && t.GetGenericTypeDefinition() == ConvertableType);
|
---|
| 17 |
|
---|
[17407] | 18 | public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) =>
|
---|
[17394] | 19 | ((dynamic)item).Value = Enum.Parse(
|
---|
[17266] | 20 | item.GetType().GenericTypeArguments.First(),
|
---|
[17410] | 21 | ((StringJsonItem)data).Value);
|
---|
[17407] | 22 |
|
---|
| 23 | public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
|
---|
[17263] | 24 | object val = ((dynamic)value).Value;
|
---|
| 25 | Type enumType = val.GetType();
|
---|
[17410] | 26 | return new StringJsonItem() {
|
---|
[17407] | 27 | Name = value.ItemName,
|
---|
[17433] | 28 | Description = value.ItemDescription,
|
---|
[17407] | 29 | Value = Enum.GetName(enumType, val),
|
---|
[17473] | 30 | ConcreteRestrictedItems = Enum.GetNames(enumType)
|
---|
[17828] | 31 | };
|
---|
[17263] | 32 | }
|
---|
| 33 | }
|
---|
| 34 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.