Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Transformer.cs @ 17263

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

#3026:

  • added first prototype for:
    • creating templates
    • initialize a optimizer out of a template
  • first attempts to create the option to extend the template generation and initialisation (with Transformers -> json To IItem, IItem to json) without serializing/deserializing the whole IItem
File size: 2.1 KB
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 ParameterTest {
10  public static class Transformer {
11    private static IDictionary<Type, ITypeTransformer> transformers = new Dictionary<Type, ITypeTransformer>();
12   
13    public static void Register(Type type, ITypeTransformer transformer) {
14      if(!transformers.ContainsKey(type))
15        transformers.Add(type, transformer);
16    }
17
18
19    public static void Register<T>(ITypeTransformer transformer) => Register(typeof(T), transformer);
20
21    public static ITypeTransformer Get(Type type) {
22      foreach (var x in transformers) {
23        if (type.IsEqualTo(x.Key)) return x.Value;
24      }
25      return null;
26    }
27
28    internal static void SetValue(IItem item, ParameterData data) {
29      Get(item.GetType()).SetValue(item, data);
30    }
31
32
33    static Transformer() {
34      Register<IntValue>(new ValueTypeValueTransformer<IntValue, int>());
35      Register<DoubleValue>(new ValueTypeValueTransformer<DoubleValue, double>());
36      Register<PercentValue>(new ValueTypeValueTransformer<PercentValue, double>());
37      Register<BoolValue>(new ValueTypeValueTransformer<BoolValue, bool>());
38      Register<DateTimeValue>(new ValueTypeValueTransformer<DateTimeValue, DateTime>());
39      Register<StringValue>(new StringValueTransformer());
40
41      Register<IntArray>(new ValueTypeArrayTransformer<IntArray, int>());
42      Register<DoubleArray>(new ValueTypeArrayTransformer<DoubleArray, double>());
43      Register<PercentArray>(new ValueTypeArrayTransformer<PercentArray, double>());
44      Register<BoolArray>(new ValueTypeArrayTransformer<BoolArray, bool>());
45
46      Register<IntMatrix>(new ValueTypeMatrixTransformer<IntMatrix, int>());
47      Register<DoubleMatrix>(new ValueTypeMatrixTransformer<DoubleMatrix, double>());
48      Register<PercentMatrix>(new ValueTypeMatrixTransformer<PercentMatrix, double>());
49      Register<BoolMatrix>(new ValueTypeMatrixTransformer<BoolMatrix, bool>());
50    }
51
52  }
53}
Note: See TracBrowser for help on using the repository browser.