Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/07/20 16:25:39 (5 years ago)
Author:
dpiringe
Message:

#3026:

  • deleted: ConvertableAttribute, DummyConverter, ObjectExtensions
  • renamed: CustomJsonWriter -> SingleLineArrayJsonWriter, JCInstantiator -> JsonTemplateInstantiator
  • added: JsonItemConverterFactory, UnsupportedJsonItem
  • IJsonItemConverter:
    • added two new properties: Priority and ConvertableType -> because converters are automatically collected by plugin infrastructure now
    • Extract, Inject references a root converter now -> typically an instance of JsonItemConverter -> to prevent cycles
  • JsonItemConverter:
    • now implements the interface IJsonItemConverter
    • is now a dynamic class
    • is only instantiable with an factory (JsonItemConverterFactory)
    • still has the old (but now public) static methods Extract and Inject (without ref param IJsonItemConverter root) -> creates instance with factory and calls methods of instance
    • removed register and unregister methods, because the factory collects all converters automatically now (on first call of Create)
    • has cycle detection for Extract and Inject
    • renamed method Get to GetConverter
Location:
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters
Files:
1 deleted
15 edited

Legend:

Unmodified
Added
Removed
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/BaseConverter.cs

    r17379 r17394  
    1111  public abstract class BaseConverter : IJsonItemConverter
    1212  {
    13     public void Inject(IItem item, JsonItem data) {
    14       InjectData(item, data);
     13    public abstract int Priority { get; }
     14    public abstract Type ConvertableType { get; }
     15
     16    public void Inject(IItem item, JsonItem data, IJsonItemConverter root) {
     17
     18      InjectData(item, data, root);
    1519    }
    1620
    17     public JsonItem Extract(IItem value) {
    18       JsonItem data = ExtractData(value);
    19       data.Name = string.IsNullOrEmpty(data.Name) ? value.ItemName : data.Name;
     21    public JsonItem Extract(IItem value, IJsonItemConverter root) {
     22      JsonItem data = new JsonItem() { Name = value.ItemName };
     23      Populate(value, data, root);
    2024      return data;
    2125    }
    2226   
    23     public abstract void InjectData(IItem item, JsonItem data);
    24     public abstract JsonItem ExtractData(IItem value);
     27    public abstract void InjectData(IItem item, JsonItem data, IJsonItemConverter root);
     28    public abstract void Populate(IItem value, JsonItem item, IJsonItemConverter root);
    2529
    2630    #region Helper
    2731    protected ValueType CastValue<ValueType>(object obj) {
    2832      if (obj is JToken)
    29         return obj.Cast<JToken>().ToObject<ValueType>();
     33        return ((JToken)obj).ToObject<ValueType>();
    3034      else if (obj is IConvertible)
    31         return Convert.ChangeType(obj, typeof(ValueType)).Cast<ValueType>();
     35        return (ValueType)Convert.ChangeType(obj, typeof(ValueType));
    3236      else return (ValueType)obj;
    3337    }
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ConstrainedValueParameterConverter.cs

    r17379 r17394  
    99namespace HeuristicLab.JsonInterface {
    1010  public class ConstrainedValueParameterConverter : ParameterBaseConverter {
    11     public override void InjectData(IParameter parameter, JsonItem data) {
     11    public override int Priority => 3;
     12    public override Type ConvertableType => typeof(IConstrainedValueParameter<>);
     13
     14    public override void InjectData(IParameter parameter, JsonItem data, IJsonItemConverter root) {
    1215      foreach(var x in GetValidValues(parameter))
    1316        if(x.ToString() == CastValue<string>(data.Value))
     
    1720        foreach(var param in data.Children) {
    1821          if(param.Name == parameter.ActualValue.ItemName)
    19             JsonItemConverter.Inject(parameter.ActualValue, param);
     22            root.Inject(parameter.ActualValue, param, root);
    2023        }
    2124      }
    2225    }
    2326
    24     public override JsonItem ExtractData(IParameter value) =>
    25       new JsonItem() {
    26         Name = value.Name,
    27         Value = value.ActualValue?.ToString(),
    28         Range = GetValidValues(value).Select(x => x.ToString()),
    29         Children = GetParameterizedChilds(value)
    30       };
     27    public override void Populate(IParameter value, JsonItem item, IJsonItemConverter root) {
     28      item.AddChilds(GetParameterizedChilds(value));
     29      item.Name = value.Name;
     30      item.Value = value.ActualValue?.ToString();
     31      item.Range = GetValidValues(value).Select(x => x.ToString());
     32    }     
    3133
    3234    #region Helper
    3335    private IItem[] GetValidValues(IParameter value) {
    3436      List<IItem> list = new List<IItem>();
    35       var values = value.Cast<dynamic>().ValidValues;
     37      var values = ((dynamic)value).ValidValues;
    3638      foreach (var x in values) list.Add((IItem)x);
    3739      return list.ToArray();
     
    4042    private IList<JsonItem> GetParameterizedChilds(IParameter value) {
    4143      List<JsonItem> list = new List<JsonItem>();
    42       var values = value.Cast<dynamic>().ValidValues;
     44      var values = ((dynamic)value).ValidValues;
    4345      foreach(var x in values) {
    4446        if (x is IParameterizedItem) {
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/EnumTypeConverter.cs

    r17342 r17394  
    99namespace HeuristicLab.JsonInterface {
    1010  public class EnumTypeConverter : BaseConverter {
    11     public override void InjectData(IItem item, JsonItem data) =>
    12       item.Cast<dynamic>().Value = Enum.Parse(
     11    public override int Priority => 1;
     12    public override Type ConvertableType => typeof(EnumValue<>);
     13
     14    public override void InjectData(IItem item, JsonItem data, IJsonItemConverter root) =>
     15      ((dynamic)item).Value = Enum.Parse(
    1316        item.GetType().GenericTypeArguments.First(),
    1417        CastValue<string>(data.Value));
    1518
    16     public override JsonItem ExtractData(IItem value) {
    17       JsonItem data = new JsonItem();
     19    public override void Populate(IItem value, JsonItem item, IJsonItemConverter root) {
    1820      object val = ((dynamic)value).Value;
    1921      Type enumType = val.GetType();
    20       data.Value = Enum.GetName(enumType, val);
    21       data.Range = Enum.GetNames(enumType);
    22       return data;
     22      item.Value = Enum.GetName(enumType, val);
     23      item.Range = Enum.GetNames(enumType);
    2324    }
    2425  }
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/LookupParameterConverter.cs

    r17342 r17394  
    88namespace HeuristicLab.JsonInterface {
    99  public class LookupParameterConverter : ParameterBaseConverter {
    10     public override JsonItem ExtractData(IParameter value) =>
    11       new JsonItem() {
    12         Name = value.Name,
    13         ActualName = value.Cast<ILookupParameter>().ActualName
    14       };
     10    public override int Priority => 3;
     11    public override Type ConvertableType => typeof(ILookupParameter);
    1512
    16     public override void InjectData(IParameter parameter, JsonItem data) =>
    17       parameter.Cast<ILookupParameter>().ActualName = data.ActualName.Cast<string>();
     13    public override void Populate(IParameter value, JsonItem item, IJsonItemConverter root) {
     14      item.Name = value.Name;
     15      item.ActualName = ((ILookupParameter)value).ActualName;
     16    }
     17
     18    public override void InjectData(IParameter parameter, JsonItem data, IJsonItemConverter root) =>
     19      ((ILookupParameter)parameter).ActualName = data.ActualName as string;
    1820  }
    1921}
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/MultiCheckedOperatorConverter.cs

    r17379 r17394  
    99namespace HeuristicLab.JsonInterface {
    1010  public class MultiCheckedOperatorConverter : ParameterizedItemConverter {
    11     public override JsonItem ExtractData(IItem value) {
    12       JsonItem data = base.ExtractData(value);
     11    public override int Priority => 3;
     12    public override Type ConvertableType => typeof(ICheckedMultiOperator<>);
    1313
    14       if(data.Children == null)
    15         data.Children = new List<JsonItem>();
    16       dynamic val = value.Cast<dynamic>();
     14    public override void Populate(IItem value, JsonItem item, IJsonItemConverter root) {
     15      base.Populate(value, item, root);
     16
     17      dynamic val = value as dynamic;
    1718      foreach (var op in val.Operators) {
    18         data.Children.Add(new JsonItem() {
     19        item.AddChilds(new JsonItem() {
    1920          Name = op.Name,
    2021          Value = val.Operators.ItemChecked(op),
     
    2223        });
    2324      }
    24       return data;
    2525    }
    2626
    27     public override void InjectData(IItem item, JsonItem data) {
    28       base.InjectData(item, data);
     27    public override void InjectData(IItem item, JsonItem data, IJsonItemConverter root) {
     28      base.InjectData(item, data, root);
    2929
    30       dynamic val = item.Cast<dynamic>();
     30      dynamic val = item as dynamic;
    3131      foreach (var op in val.Operators)
    3232        val.Operators.SetItemCheckedState(op, GetOperatorState(op.Name, data));
     
    3535    private bool GetOperatorState(string name, JsonItem data) {
    3636      foreach(var op in data.Children) {
    37         if (op.Name == name && op.Value is bool) return op.Value.Cast<bool>();
     37        if (op.Name == name && op.Value is bool) return (bool)op.Value;
    3838      }
    3939      return false;
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ParameterBaseConverter.cs

    r17379 r17394  
    88namespace HeuristicLab.JsonInterface {
    99  public abstract class ParameterBaseConverter : BaseConverter {
    10     public override JsonItem ExtractData(IItem value) =>
    11       ExtractData(value.Cast<IParameter>());
     10    public override void Populate(IItem value, JsonItem item, IJsonItemConverter root) =>
     11      Populate(value as IParameter, item, root);
    1212
    13     public abstract JsonItem ExtractData(IParameter value);
     13    public abstract void Populate(IParameter value, JsonItem item, IJsonItemConverter root);
    1414
    15     public override void InjectData(IItem item, JsonItem data) => InjectData(item.Cast<IParameter>(), data);
     15    public override void InjectData(IItem item, JsonItem data, IJsonItemConverter root) =>
     16      InjectData(item as IParameter, data, root);
    1617
    17     public abstract void InjectData(IParameter parameter, JsonItem data);
     18    public abstract void InjectData(IParameter parameter, JsonItem data, IJsonItemConverter root);
    1819  }
    1920}
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ParameterizedItemConverter.cs

    r17379 r17394  
    88namespace HeuristicLab.JsonInterface {
    99  public class ParameterizedItemConverter : BaseConverter {
    10     public override void InjectData(IItem item, JsonItem data) {
    11       IParameterizedItem pItem = item.Cast<IParameterizedItem>();
     10    public override int Priority => 2;
     11    public override Type ConvertableType => typeof(IParameterizedItem);
     12
     13    public override void InjectData(IItem item, JsonItem data, IJsonItemConverter root) {
     14      IParameterizedItem pItem = item as IParameterizedItem;
    1215
    1316      if(data.Children != null) {
    1417        foreach (var sp in data.Children)
    1518          if (pItem.Parameters.TryGetValue(sp.Name, out IParameter param))
    16             JsonItemConverter.Inject(param, sp);
     19            root.Inject(param, sp, root);
    1720      }
    1821    }
    1922
    20     public override JsonItem ExtractData(IItem value) {
    21       JsonItem item = new JsonItem();
     23    public override void Populate(IItem value, JsonItem item, IJsonItemConverter root) {
    2224      var parameterizedItem = value as IParameterizedItem;
    2325
    2426      foreach (var param in parameterizedItem.Parameters) {
    25         if(!param.Hidden) {
    26           JsonItem data = JsonItemConverter.Extract(param);
    27           //data.Name = param.Name;
    28 
    29           if (item.Children == null)
    30             item.Children = new List<JsonItem>();
    31           item.Children.Add(data);
    32         }
     27        if(!param.Hidden)
     28          item.AddChilds(root.Extract(param, root));
    3329      }
    34       return item;
    3530    }
    3631  }
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/RegressionProblemDataConverter.cs

    r17379 r17394  
    1111  public class RegressionProblemDataConverter : BaseConverter {
    1212    private const BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
    13     public override JsonItem ExtractData(IItem value) {
    14       JsonItem item = new JsonItem() {
    15         Path = value.ItemName,
    16         Children = new List<JsonItem>()
    17       };
    18      
     13    public override int Priority => 20;
     14    public override Type ConvertableType => HEAL.Attic.Mapper.StaticCache.GetType(new Guid("EE612297-B1AF-42D2-BF21-AF9A2D42791C"));
     15
     16    public override void Populate(IItem value, JsonItem item, IJsonItemConverter root) {     
    1917      dynamic val = (dynamic)value;
    2018      object dataset = (object)val.Dataset;
     
    2220      FieldInfo dataInfo = dataset.GetType().GetField("storableData", flags);
    2321      // TODO: aufteilen in trainings und test daten abschnitte
    24       item.Children.Add(new JsonItem() {
     22      item.AddChilds(new JsonItem() {
    2523        Name = "Dataset",
    26         Value = dataInfo.GetValue(dataset),
    27         Path = "Dataset"
     24        Value = dataInfo.GetValue(dataset)
    2825      });
    2926
    3027      IEnumerable<StringValue> variables = (IEnumerable<StringValue>)val.InputVariables;
    31       item.Children.Add(new JsonItem() {
     28      item.AddChilds(new JsonItem() {
    3229        Name = "TargetVariable",
    3330        Value = (object)targetVariable,
    34         Range = variables.Select(x => x.Value),
    35         Path = "TargetVariable"
     31        Range = variables.Select(x => x.Value)
    3632      });
    3733
    3834
    39       item.Children.Add(new JsonItem() {
     35      item.AddChilds(new JsonItem() {
    4036        Name = "AllowedInputVariables",
    4137        Value = (object)val.AllowedInputVariables,
    42         Range = variables.Select(x => x.Value),
    43         Path = "AllowedInputVariables"
     38        Range = variables.Select(x => x.Value)
    4439      });
    45 
    46       item.UpdatePath();
    47 
    48       return item;
    4940    }
    5041
    51     public override void InjectData(IItem item, JsonItem data) {
     42    public override void InjectData(IItem item, JsonItem data, IJsonItemConverter root) {
    5243      // TODO: inject data
    5344      throw new NotImplementedException();
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/StringValueConverter.cs

    r17342 r17394  
    99namespace HeuristicLab.JsonInterface {
    1010  public class StringValueConverter : BaseConverter {
    11     public override void InjectData(IItem item, JsonItem data) =>
    12       item.Cast<StringValue>().Value = CastValue<string>(data.Value);
     11    public override int Priority => 1;
     12    public override Type ConvertableType => typeof(StringValue);
    1313
    14     public override JsonItem ExtractData(IItem value) =>
    15       new JsonItem() {
    16         Value = value.Cast<StringValue>().Value
    17       };
     14    public override void InjectData(IItem item, JsonItem data, IJsonItemConverter root) =>
     15      ((StringValue)item).Value = CastValue<string>(data.Value);
     16
     17    public override void Populate(IItem value, JsonItem item, IJsonItemConverter root) =>
     18      item.Value = ((StringValue)value).Value;
    1819  }
    1920}
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueLookupParameterConverter.cs

    r17379 r17394  
    88namespace HeuristicLab.JsonInterface {
    99  public class ValueLookupParameterConverter : ParameterBaseConverter {
    10     public override JsonItem ExtractData(IParameter value) {
    11       IValueLookupParameter param = value.Cast<IValueLookupParameter>();
     10    public override int Priority => 4;
     11    public override Type ConvertableType => typeof(IValueLookupParameter);
     12
     13    public override void Populate(IParameter value, JsonItem item, IJsonItemConverter root) {
     14      IValueLookupParameter param = value as IValueLookupParameter;
     15     
     16      item.Name = value.Name;
     17      item.ActualName = param.ActualName;
     18
    1219      object actualValue = null;
    1320      IEnumerable<object> actualRange = null;
    1421      if(param.Value != null) {
    15         JsonItem tmp = JsonItemConverter.Extract(param.Value);
     22        JsonItem tmp = root.Extract(param.Value, root);
     23        tmp.Parent = item;
    1624        actualValue = tmp.Value;
    1725        actualRange = tmp.Range;
     
    1927        actualRange = new object[] { GetMinValue(param.DataType), GetMaxValue(param.DataType) };
    2028      }
    21 
    22       return new JsonItem() {
    23         Name = value.Name,
    24         ActualName = param.ActualName,
    25         Value = actualValue,
    26         Range = actualRange
    27       };
     29      item.Value = actualValue;
     30      item.Range = actualRange;
    2831    }
    2932
    30     public override void InjectData(IParameter parameter, JsonItem data) {
    31       IValueLookupParameter param = parameter.Cast<IValueLookupParameter>();
     33    public override void InjectData(IParameter parameter, JsonItem data, IJsonItemConverter root) {
     34      IValueLookupParameter param = parameter as IValueLookupParameter;
    3235      param.ActualName = CastValue<string>(data.ActualName);
    3336      if (param.Value != null)
    34         JsonItemConverter.Inject(param.Value, data);
     37        root.Inject(param.Value, data, root);
    3538    }
    3639  }
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueParameterConverter.cs

    r17374 r17394  
    88namespace HeuristicLab.JsonInterface {
    99  public class ValueParameterConverter : ParameterBaseConverter {
     10    public override int Priority => 2;
     11    public override Type ConvertableType => typeof(IValueParameter);
    1012
    11     public override void InjectData(IParameter parameter, JsonItem data) {
     13    public override void InjectData(IParameter parameter, JsonItem data, IJsonItemConverter root) {
    1214      if (parameter.ActualValue == null && data.Value != null)
    1315        parameter.ActualValue = Instantiate(parameter.DataType);
    14       JsonItemConverter.Inject(parameter.ActualValue, data);
     16      root.Inject(parameter.ActualValue, data, root);
    1517    }
    1618
    17     public override JsonItem ExtractData(IParameter value) {
    18       JsonItem data = new JsonItem() { Name = value.Name };
     19    public override void Populate(IParameter value, JsonItem item, IJsonItemConverter root) {
     20      item.Name = value.Name;
    1921      if (value.ActualValue != null) {
    20         JsonItem tmp = JsonItemConverter.Extract(value.ActualValue);
     22        JsonItem tmp = root.Extract(value.ActualValue, root);
    2123        if(tmp.Name == "[OverridableParamName]") {
    2224          tmp.Name = value.Name;
    23           data = tmp;
     25          JsonItem.Merge(item, tmp);
    2426        }
    2527        else
    26           data.AddParameter(tmp);
     28          item.AddChilds(tmp);
    2729      }
    28       return data;
    2930    }
    3031  }
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueRangeConverter.cs

    r17379 r17394  
    1111namespace HeuristicLab.JsonInterface {
    1212
    13   public class IntRangeConverter : ValueRangeConverter<IntRange, IntValue, int> { }
    14   public class DoubleRangeConverter : ValueRangeConverter<DoubleRange, DoubleValue, double> {}
     13  public class IntRangeConverter : ValueRangeConverter<IntRange, IntValue, int> {
     14    public override int Priority => 1;
     15    public override Type ConvertableType => typeof(IntRange);
     16  }
     17  public class DoubleRangeConverter : ValueRangeConverter<DoubleRange, DoubleValue, double> {
     18    public override int Priority => 1;
     19    public override Type ConvertableType => typeof(DoubleRange);
     20  }
    1521
    16   public class ValueRangeConverter<RangeType, T, TType> : BaseConverter
     22  public abstract class ValueRangeConverter<RangeType, T, TType> : BaseConverter
    1723    where RangeType : StringConvertibleValueTuple<T, T>
    1824    where T : ValueTypeValue<TType>, IDeepCloneable, IStringConvertibleValue
     
    2127    private const BindingFlags Flags = BindingFlags.NonPublic | BindingFlags.Instance;
    2228
    23     public override JsonItem ExtractData(IItem value) {
     29    public override void Populate(IItem value, JsonItem item, IJsonItemConverter root) {
    2430      var field = value.GetType().GetField("values", Flags);
    2531      Tuple<T,T> tuple = (Tuple<T,T>)field.GetValue(value);
    26 
    27       return new JsonItem() {
    28         Name = "[OverridableParamName]",
    29         Value = new object[] { tuple.Item1.Value, tuple.Item2.Value },
    30         Range = new object[] { GetMinValue(tuple.Item1.Value.GetType()),
    31                                GetMaxValue(tuple.Item2.Value.GetType()) }
    32       };
     32      item.Name = "[OverridableParamName]";
     33      item.Value = new object[] { tuple.Item1.Value, tuple.Item2.Value };
     34      item.Range = new object[] { GetMinValue(tuple.Item1.Value.GetType()), GetMaxValue(tuple.Item2.Value.GetType()) };
    3335    }
    3436
    35     public override void InjectData(IItem item, JsonItem data) {
     37    public override void InjectData(IItem item, JsonItem data, IJsonItemConverter root) {
    3638      object[] arr = (object[])data.Value;
    3739      Tuple<T,T> tuple = new Tuple<T,T>(Instantiate<T>(arr[0]), Instantiate<T>(arr[1]));
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueTypeArrayConverter.cs

    r17374 r17394  
    99
    1010namespace HeuristicLab.JsonInterface {
    11   public class ValueTypeArrayConverter<ArrayType, T> : BaseConverter
     11
     12  public class IntArrayConverter : ValueTypeArrayConverter<IntArray, int> {
     13    public override int Priority => 1;
     14    public override Type ConvertableType => typeof(IntArray);
     15  }
     16
     17  public class DoubleArrayConverter : ValueTypeArrayConverter<DoubleArray, double> {
     18    public override int Priority => 1;
     19    public override Type ConvertableType => typeof(DoubleArray);
     20  }
     21
     22  public class PercentArrayConverter : ValueTypeArrayConverter<PercentArray, double> {
     23    public override int Priority => 2;
     24    public override Type ConvertableType => typeof(PercentArray);
     25  }
     26
     27  public class BoolArrayConverter : ValueTypeArrayConverter<BoolArray, bool> {
     28    public override int Priority => 1;
     29    public override Type ConvertableType => typeof(BoolArray);
     30  }
     31
     32  public abstract class ValueTypeArrayConverter<ArrayType, T> : BaseConverter
    1233    where ArrayType : ValueTypeArray<T>
    1334    where T : struct
    1435  {
    15     public override void InjectData(IItem item, JsonItem data) =>
    16       CopyArrayData(item.Cast<ArrayType>(), CastValue<T[]>(data.Value));
     36    public override void InjectData(IItem item, JsonItem data, IJsonItemConverter root) =>
     37      CopyArrayData(((ArrayType)item), CastValue<T[]>(data.Value));
    1738
    18     public override JsonItem ExtractData(IItem value) =>
    19       new JsonItem() {
    20         Name = "[OverridableParamName]",
    21         Value = value.Cast<ArrayType>().CloneAsArray()
    22       };
     39    public override void Populate(IItem value, JsonItem item, IJsonItemConverter root) {
     40      item.Name = "[OverridableParamName]";
     41      item.Value = ((ArrayType)value).CloneAsArray();
     42    }
    2343
    2444    #region Helper
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueTypeMatrixConverter.cs

    r17379 r17394  
    99
    1010namespace HeuristicLab.JsonInterface {
    11   public class ValueTypeMatrixConverter<MatrixType, T> : BaseConverter
     11  public class IntMatrixConverter : ValueTypeMatrixConverter<IntMatrix, int> {
     12    public override int Priority => 1;
     13    public override Type ConvertableType => typeof(IntMatrix);
     14  }
     15
     16  public class DoubleMatrixConverter : ValueTypeMatrixConverter<DoubleMatrix, double> {
     17    public override int Priority => 1;
     18    public override Type ConvertableType => typeof(DoubleMatrix);
     19  }
     20
     21  public class PercentMatrixConverter : ValueTypeMatrixConverter<PercentMatrix, double> {
     22    public override int Priority => 2;
     23    public override Type ConvertableType => typeof(PercentMatrix);
     24  }
     25
     26  public class BoolMatrixConverter : ValueTypeMatrixConverter<BoolMatrix, bool> {
     27    public override int Priority => 1;
     28    public override Type ConvertableType => typeof(BoolMatrix);
     29  }
     30
     31  public abstract class ValueTypeMatrixConverter<MatrixType, T> : BaseConverter
    1232    where MatrixType : ValueTypeMatrix<T>
    1333    where T : struct
    1434  {
    15     public override void InjectData(IItem item, JsonItem data) =>
    16       CopyMatrixData(item.Cast<MatrixType>(), data.Value);
     35    public override void InjectData(IItem item, JsonItem data, IJsonItemConverter root) =>
     36      CopyMatrixData(item as MatrixType, data.Value);
    1737
    18     public override JsonItem ExtractData(IItem value) =>
    19       new JsonItem() {
    20         Name = "[OverridableParamName]",
    21         Value = value.Cast<MatrixType>().CloneAsMatrix()
    22       };
     38    public override void Populate(IItem value, JsonItem item, IJsonItemConverter root) {
     39      item.Name = "[OverridableParamName]";
     40      item.Value = ((MatrixType)value).CloneAsMatrix();
     41    }
    2342
    2443    #region Helper
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueTypeValueConverter.cs

    r17374 r17394  
    88
    99namespace HeuristicLab.JsonInterface {
    10   public class ValueTypeValueConverter<ValueType, T> : BaseConverter
     10
     11  public class IntValueConverter : ValueTypeValueConverter<IntValue, int> {
     12    public override int Priority => 1;
     13    public override Type ConvertableType => typeof(IntValue);
     14  }
     15
     16  public class DoubleValueConverter : ValueTypeValueConverter<DoubleValue, double> {
     17    public override int Priority => 1;
     18    public override Type ConvertableType => typeof(DoubleValue);
     19  }
     20
     21  public class PercentValueConverter : ValueTypeValueConverter<PercentValue, double> {
     22    public override int Priority => 2;
     23    public override Type ConvertableType => typeof(PercentValue);
     24  }
     25
     26  public class BoolValueConverter : ValueTypeValueConverter<BoolValue, bool> {
     27    public override int Priority => 1;
     28    public override Type ConvertableType => typeof(BoolValue);
     29  }
     30
     31  public class DateTimeValueConverter : ValueTypeValueConverter<DateTimeValue, DateTime> {
     32    public override int Priority => 1;
     33    public override Type ConvertableType => typeof(DateTimeValue);
     34  }
     35
     36  public abstract class ValueTypeValueConverter<ValueType, T> : BaseConverter
    1137    where ValueType : ValueTypeValue<T>
    1238    where T : struct {
    1339
    14     public override void InjectData(IItem item, JsonItem data) =>
    15       item.Cast<ValueType>().Value = CastValue<T>(data.Value);
     40    public override void InjectData(IItem item, JsonItem data, IJsonItemConverter root) =>
     41      ((ValueType)item).Value = CastValue<T>(data.Value);
    1642
    17     public override JsonItem ExtractData(IItem value) =>
    18       new JsonItem() {
    19         Name = "[OverridableParamName]",
    20         Value = value.Cast<ValueType>().Value,
    21         Range = new object[] { GetMinValue(typeof(T)), GetMaxValue(typeof(T)) }
    22       };
     43    public override void Populate(IItem value, JsonItem item, IJsonItemConverter root) {
     44      item.Name = "[OverridableParamName]";
     45      item.Value = ((ValueType)value).Value;
     46      item.Range = new object[] { GetMinValue(typeof(T)), GetMaxValue(typeof(T)) };
     47    }
    2348  }
    2449}
Note: See TracChangeset for help on using the changeset viewer.