using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; namespace HeuristicLab.JsonInterface { public class IntRangeConverter : ValueRangeConverter { public override int Priority => 1; public override Type ConvertableType => typeof(IntRange); } public class DoubleRangeConverter : ValueRangeConverter { public override int Priority => 1; public override Type ConvertableType => typeof(DoubleRange); } public abstract class ValueRangeConverter : BaseConverter where RangeType : StringConvertibleValueTuple where T : ValueTypeValue, IDeepCloneable, IStringConvertibleValue where TType : struct { private const BindingFlags Flags = BindingFlags.NonPublic | BindingFlags.Instance; public override void Populate(IItem value, JsonItem item, IJsonItemConverter root) { var field = value.GetType().GetField("values", Flags); Tuple tuple = (Tuple)field.GetValue(value); item.Name = "[OverridableParamName]"; item.Value = new object[] { tuple.Item1.Value, tuple.Item2.Value }; item.Range = new object[] { GetMinValue(tuple.Item1.Value.GetType()), GetMaxValue(tuple.Item2.Value.GetType()) }; } public override void InjectData(IItem item, JsonItem data, IJsonItemConverter root) { object[] arr = (object[])data.Value; Tuple tuple = new Tuple(Instantiate(arr[0]), Instantiate(arr[1])); var field = item.GetType().GetField("values", Flags); field.SetValue(tuple, item); } } }