Ignore:
Timestamp:
11/24/15 18:32:55 (7 years ago)
Author:
swagner
Message:

#2520: Worked on new persistence implementation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Transformers/Transformers.cs

    r13386 r13387  
    329329  }
    330330
    331   [Transformer("BA55C7A6-C91E-4351-A889-E4A7E647F16D", 213)]
     331  [Transformer("BA55C7A6-C91E-4351-A889-E4A7E647F16D", 212)]
    332332  internal sealed class DateTimeTransformer : LongBoxTransformer<DateTime> {
    333333    protected override long ToBoxType(DateTime value, Mapper mapper) { return value.Ticks; }
     
    335335  }
    336336
    337   [Transformer("0C91441B-2D97-432B-B493-D6EC483FC5AD", 214)]
     337  [Transformer("0C91441B-2D97-432B-B493-D6EC483FC5AD", 213)]
    338338  internal sealed class TimeSpanTransformer : LongBoxTransformer<TimeSpan> {
    339339    protected override long ToBoxType(TimeSpan value, Mapper mapper) { return value.Ticks; }
    340340    protected override TimeSpan ToValueType(long value, Type type, Mapper mapper) { return new TimeSpan(value); }
    341341  }
    342   [Transformer("0B540EAC-79AB-40CF-8277-D2C81135FEB6", 217)]
     342
     343  [Transformer("0B540EAC-79AB-40CF-8277-D2C81135FEB6", 214)]
    343344  internal sealed class ColorTransformers : IntBoxTransformer<Color> {
    344345    protected override int ToBoxType(Color value, Mapper mapper) { return value.ToArgb(); }
    345346    protected override Color ToValueType(int value, Type type, Mapper mapper) { return Color.FromArgb(value); }
    346347  }
     348
     349  [Transformer("2E6D4A40-B4BE-425F-8E35-2D7C00054639", 215)]
     350  internal sealed class PointTransformer : IntArrayBoxTransformer<Point> {
     351    protected override IEnumerable<int> ToBoxType(Point value, Mapper mapper) { return new int[] { value.X, value.Y }; }
     352    protected override Point ToValueType(IEnumerable<int> value, Type type, Mapper mapper) { return new Point(value.ElementAt(0), value.ElementAt(1)); }
     353  }
     354
     355  [Transformer("97B5CFC8-CDFA-4EB5-B4CD-5B3CFA5CD844", 216)]
     356  internal sealed class KeyValuePairTransformer : UnsignedIntArrayBoxTransformer<object> {
     357    public override bool CanTransformType(Type type) {
     358      return type.IsGenericType && (type.GetGenericTypeDefinition() == typeof(KeyValuePair<,>));
     359    }
     360    protected override IEnumerable<uint> ToBoxType(object value, Mapper mapper) {
     361      var type = value.GetType();
     362      var pair = new uint[2];
     363      pair[0] = mapper.GetBoxId(type.GetProperty("Key").GetValue(value));
     364      pair[1] = mapper.GetBoxId(type.GetProperty("Value").GetValue(value));
     365      return pair;
     366    }
     367    protected override object ToValueType(IEnumerable<uint> value, Type type, Mapper mapper) {
     368      var key = mapper.GetObject(value.ElementAt(0));
     369      var val = mapper.GetObject(value.ElementAt(1));
     370      return Activator.CreateInstance(type, key, val);
     371    }
     372  }
    347373  #endregion
    348374
    349375  #region String
    350   [Transformer("E75A594C-0034-4DAB-B28E-8F84F9F6DE8D", 215)]
     376  [Transformer("E75A594C-0034-4DAB-B28E-8F84F9F6DE8D", 217)]
    351377  internal sealed class StringTransformer : UnsignedIntBoxTransformer<string> {
    352378    protected override uint ToBoxType(string value, Mapper mapper) { return mapper.GetStringId(value); }
     
    356382
    357383  #region Enum
    358   [Transformer("93FF076B-BC4B-4C39-8C40-15E004468C98", 216)]
     384  [Transformer("93FF076B-BC4B-4C39-8C40-15E004468C98", 218)]
    359385  internal sealed class EnumTransformer : UnsignedIntBoxTransformer<object> {
    360386    public override bool CanTransformType(Type type) {
     
    371397
    372398  #region Type
    373   [Transformer("8D17FD28-383B-44E9-9BBF-B19D351C5E38", 218)]
     399  [Transformer("8D17FD28-383B-44E9-9BBF-B19D351C5E38", 219)]
    374400  internal sealed class TypeTransformer : UnsignedIntBoxTransformer<Type> {
    375401    public override bool CanTransformType(Type type) {
     
    381407  #endregion
    382408
    383   #region Primitive Array Types
     409  #region Array Types
    384410  [Transformer("F25A73B2-6B67-4493-BD59-B836AF4455D1", 300)]
    385411  internal sealed class BoolArrayTransformer : BoolArrayBoxTransformer<bool[]> {
     
    459485    protected override string[] ToValueType(IEnumerable<string> value, Type type, Mapper mapper) { return value.ToArray(); }
    460486  }
     487
     488  [Transformer("C83F0B5A-68D8-4271-81F9-FF259FC6F126", 400)]
     489  internal sealed class GenericArrayTransformer : UnsignedIntArrayBoxTransformer<object> {
     490    public override bool CanTransformType(Type type) {
     491      return type.IsArray;
     492    }
     493    protected override IEnumerable<uint> ToBoxType(object value, Mapper mapper) {
     494      var arr = (object[])value;
     495      return arr.Select(x => mapper.GetBoxId(x));
     496    }
     497    protected override object ToValueType(IEnumerable<uint> value, Type type, Mapper mapper) {
     498      return value.Select(x => mapper.GetObject(x)).ToArray();
     499    }
     500  }
    461501  #endregion
    462502}
Note: See TracChangeset for help on using the changeset viewer.