Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/TypeTransformer/EnumTypeTransformer.cs @ 17266

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

#3026:

  • changed the namespace from ParameterTest to HeuristicLab.Manufacture
  • added an extension method for Type to get the distance of an interface based on the target type
  • renamed methods ToData, SetValue to Extract, Inject
  • new implementation of the template generation with transformers (not the final name)
  • started to use the new transformers for the instantiation of IOptimizer-objects (out of a template)
  • new transformers: LookupParameterTransformer and DummyTransformer
File size: 818 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.Manufacture {
10  public class EnumTypeTransformer : BaseTransformer {
11
12    public override void InjectData(IItem item, ParameterData data) =>
13      item.Cast<dynamic>().Value = Enum.Parse(
14        item.GetType().GenericTypeArguments.First(),
15        CastValue<string>(data.Default));
16
17    public override ParameterData ExtractData(IItem value) {
18      ParameterData data = new ParameterData();
19      object val = ((dynamic)value).Value;
20      Type enumType = val.GetType();
21      data.Default = Enum.GetName(enumType, val);
22      data.Range = Enum.GetNames(enumType);
23      return data;
24    }
25  }
26}
Note: See TracBrowser for help on using the repository browser.