Changeset 17266 for branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/TypeTransformer/ValueTypeValueTransformer.cs
- Timestamp:
- 09/20/19 16:23:42 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/TypeTransformer/ValueTypeValueTransformer.cs
r17263 r17266 7 7 using HeuristicLab.Data; 8 8 9 namespace ParameterTest{9 namespace HeuristicLab.Manufacture { 10 10 public class ValueTypeValueTransformer<ValueType, T> : BaseTransformer 11 11 where ValueType : ValueTypeValue<T> 12 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) => 13 14 public override void InjectData(IItem item, ParameterData data) => 17 15 item.Cast<ValueType>().Value = CastValue<T>(data.Default); 18 16 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 } 17 public override ParameterData ExtractData(IItem value) => 18 new ParameterData() { 19 Default = value.Cast<ValueType>().Value, 20 Range = new object[] { default(T), GetMaxValue() } 21 }; 25 22 23 #region Helper 26 24 private object GetMaxValue() { 27 25 TypeCode typeCode = Type.GetTypeCode(typeof(T)); 26 27 if (typeof(ValueType).IsEqualTo(typeof(PercentValue))) 28 return 1.0d; 29 28 30 switch (typeCode) { 29 31 case TypeCode.Int16: return Int16.MaxValue; … … 41 43 } 42 44 } 45 #endregion 43 46 } 44 47 }
Note: See TracChangeset
for help on using the changeset viewer.