Last change
on this file since 17275 was
17275,
checked in by dpiringe, 5 years ago
|
#3026
- deleted Util.cs
- BaseTransformer merges now the component with its reference (if a reference exists) -> easier handling for transformers with parameterizedItems
- MultiCheckedOperatorTransformer now sets the type name as default value
- added a type list at the end of the template file -> is needed to instantiate objects
- changed JCGenerator and JCInstantiator to test a format where FreeParameters and StaticParameters are saved as single Parameter array
|
File size:
1.3 KB
|
Line | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.Threading.Tasks;
|
---|
6 | using HeuristicLab.Core;
|
---|
7 | using Newtonsoft.Json.Linq;
|
---|
8 |
|
---|
9 | namespace HeuristicLab.Manufacture {
|
---|
10 | public abstract class BaseTransformer : ITypeTransformer
|
---|
11 | {
|
---|
12 | public Component Extract(IItem value) {
|
---|
13 | Component data = ExtractData(value);
|
---|
14 | data.Name = String.IsNullOrEmpty(data.Name) ? value.ItemName : data.Name;
|
---|
15 | return data;
|
---|
16 | }
|
---|
17 |
|
---|
18 | public void Inject(IItem item, Component data) {
|
---|
19 | if(data.Reference != null) {
|
---|
20 | Component.Merge(data, data.Reference);
|
---|
21 | }
|
---|
22 | InjectData(item, data);
|
---|
23 | }
|
---|
24 |
|
---|
25 | public abstract void InjectData(IItem item, Component data);
|
---|
26 | public abstract Component ExtractData(IItem value);
|
---|
27 |
|
---|
28 | #region Helper
|
---|
29 | protected ValueType CastValue<ValueType>(object obj) {
|
---|
30 | if (obj is JToken)
|
---|
31 | return (obj.Cast<JToken>()).ToObject<ValueType>();
|
---|
32 | else if (obj is IConvertible)
|
---|
33 | return Convert.ChangeType(obj, typeof(ValueType)).Cast<ValueType>();
|
---|
34 | else return (ValueType)obj;
|
---|
35 | }
|
---|
36 |
|
---|
37 | protected IItem Instantiate(Type type, params object[] args) =>
|
---|
38 | (IItem)Activator.CreateInstance(type,args);
|
---|
39 |
|
---|
40 | protected IItem Instantiate<T>(params object[] args) => Instantiate(typeof(T), args);
|
---|
41 | #endregion
|
---|
42 | }
|
---|
43 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.