Last change
on this file since 17843 was
17843,
checked in by dpiringe, 3 years ago
|
#3026
- removed property ConvertableType from all converters
- removed the option to fixate or loosen the path of JsonItems (obsolete)
- added a abstract formatter SymbolicRegressionSolutionFormatterBase as base formatter for ISymbolicRegressionSolution
- unified the construction of exporter controls
- code cleanup
|
File size:
1.1 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 | using HeuristicLab.Data;
|
---|
8 |
|
---|
9 | namespace HeuristicLab.JsonInterface {
|
---|
10 | public class EnumTypeConverter : BaseConverter {
|
---|
11 | public override int Priority => 1;
|
---|
12 |
|
---|
13 | public override bool CanConvertType(Type t) =>
|
---|
14 | typeof(EnumValue<>).IsAssignableFrom(t) ||
|
---|
15 | (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(EnumValue<>));
|
---|
16 |
|
---|
17 | public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) =>
|
---|
18 | ((dynamic)item).Value = Enum.Parse(
|
---|
19 | item.GetType().GenericTypeArguments.First(),
|
---|
20 | ((StringJsonItem)data).Value);
|
---|
21 |
|
---|
22 | public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
|
---|
23 | object val = ((dynamic)value).Value;
|
---|
24 | Type enumType = val.GetType();
|
---|
25 | return new StringJsonItem() {
|
---|
26 | Name = value.ItemName,
|
---|
27 | Description = value.ItemDescription,
|
---|
28 | Value = Enum.GetName(enumType, val),
|
---|
29 | ConcreteRestrictedItems = Enum.GetNames(enumType)
|
---|
30 | };
|
---|
31 | }
|
---|
32 | }
|
---|
33 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.