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
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.