Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/EnumTypeConverter.cs @ 17342

Last change on this file since 17342 was 17342, checked in by dpiringe, 5 years ago

#3026

  • in JsonItem:
    • renamed property Default to Value
    • removed usage of Reference for ValueLookupParameter
    • created new property ActualName for the actual name and using property Value for the value of an ValueLookupParameter
  • fixed a bug in ValueTypeMatrixConverter -> now it correctly resizes ValueTypeMatrix<T>
  • fixed a bug in ValueParameterConverter -> when ActualValue is null, but there is data for it, a new instance will get created
File size: 790 bytes
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6using HeuristicLab.Core;
7using HeuristicLab.Data;
8
9namespace HeuristicLab.JsonInterface {
10  public class EnumTypeConverter : BaseConverter {
11    public override void InjectData(IItem item, JsonItem data) =>
12      item.Cast<dynamic>().Value = Enum.Parse(
13        item.GetType().GenericTypeArguments.First(),
14        CastValue<string>(data.Value));
15
16    public override JsonItem ExtractData(IItem value) {
17      JsonItem data = new JsonItem();
18      object val = ((dynamic)value).Value;
19      Type enumType = val.GetType();
20      data.Value = Enum.GetName(enumType, val);
21      data.Range = Enum.GetNames(enumType);
22      return data;
23    }
24  }
25}
Note: See TracBrowser for help on using the repository browser.