Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/TypeTransformer/BaseTransformer.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: 941 bytes
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6using HeuristicLab.Core;
7using Newtonsoft.Json.Linq;
8
9namespace ParameterTest {
10  public abstract class BaseTransformer : ITypeTransformer
11  {
12    public abstract void SetValue(IItem item, ParameterData data);
13    public abstract IItem FromData(ParameterData obj, Type targetType);
14    public virtual ParameterData ToData(IItem value) =>
15      new ParameterData() { Name = value.ItemName };
16
17    protected ValueType CastValue<ValueType>(object obj) {
18      if (obj is JToken)
19        return ((JToken)obj).ToObject<ValueType>();
20      else
21        return (ValueType)obj;
22    }
23
24    protected IItem Instantiate(Type type, params object[] args) =>
25      (IItem)Activator.CreateInstance(type,args);
26
27    protected IItem Instantiate<T>(params object[] args) => Instantiate(typeof(T), args);
28  }
29}
Note: See TracBrowser for help on using the repository browser.