Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/TypeTransformer/ValueTypeValueTransformer.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: 1.7 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 class ValueTypeValueTransformer<ValueType, T> : BaseTransformer
11    where ValueType : ValueTypeValue<T>
12    where T : struct {
13    public override IItem FromData(ParameterData obj, Type targetType) =>
14      //item.Cast<ValueType>().Value = CastValue<T>(obj.Default);
15      Instantiate<ValueType>(CastValue<T>(obj.Default));
16    public override void SetValue(IItem item, ParameterData data) =>
17      item.Cast<ValueType>().Value = CastValue<T>(data.Default);
18
19    public override ParameterData ToData(IItem value) {
20      ParameterData data = base.ToData(value);
21      data.Default = value.Cast<ValueType>().Value;
22      data.Range = new object[] { default(T), GetMaxValue() };
23      return data;
24    }
25
26    private object GetMaxValue() {
27      TypeCode typeCode = Type.GetTypeCode(typeof(T));
28      switch (typeCode) {
29        case TypeCode.Int16: return Int16.MaxValue;
30        case TypeCode.Int32: return Int32.MaxValue;
31        case TypeCode.Int64: return Int64.MaxValue;
32        case TypeCode.UInt16: return UInt16.MaxValue;
33        case TypeCode.UInt32: return UInt32.MaxValue;
34        case TypeCode.UInt64: return UInt64.MaxValue;
35        case TypeCode.Single: return Single.MaxValue;
36        case TypeCode.Double: return Double.MaxValue;
37        case TypeCode.Decimal: return Decimal.MaxValue;
38        case TypeCode.Byte: return Byte.MaxValue;
39        case TypeCode.Boolean: return true;
40        default: return default(T);
41      }
42    }
43  }
44}
Note: See TracBrowser for help on using the repository browser.