Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/Hyperion/SerializerFactories/ArraySerializerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
using System;
using System.Collections.Concurrent;
using System.IO;
using System.Linq;
using System.Reflection;
using Hyperion.Extensions;
using Hyperion.ValueSerializers;

Expand All @@ -30,11 +32,23 @@ private static void WriteValues<T>(T[] array, Stream stream, Type elementType, V
stream.WriteObject(value, elementType, elementSerializer, preserveObjectReferences, session);
}
}
private static void ReadValues<T>(int length, Stream stream, DeserializerSession session, T[] array)
private static void ReadValues<T>(Serializer serializer, int length, Stream stream, DeserializerSession session, T[] array)
{
for (var i = 0; i < length; i++)
{
var value = (T)stream.ReadObject(session);
var obj = stream.ReadObject(session);
var surrogate = serializer.Options.Surrogates.FirstOrDefault(s =>
s.To.GetTypeInfo().IsInstanceOfType(obj) && s.From.IsAssignableFrom(typeof(T)));

T value;
if (surrogate != null)
{
value = (T)surrogate.FromSurrogate(obj);
} else
{
value = (T)obj;
}

array[i] = value;
}
}
Expand All @@ -57,7 +71,7 @@ public override ValueSerializer BuildSerializer(Serializer serializer, Type type
session.TrackDeserializedObject(array);
}

ReadValues(length, stream, session, (dynamic)array);
ReadValues(serializer, length, stream, session, (dynamic)array);

return array;
};
Expand Down