diff --git a/src/Hyperion/SerializerFactories/ArraySerializerFactory.cs b/src/Hyperion/SerializerFactories/ArraySerializerFactory.cs index 797d635b..9ce533b7 100644 --- a/src/Hyperion/SerializerFactories/ArraySerializerFactory.cs +++ b/src/Hyperion/SerializerFactories/ArraySerializerFactory.cs @@ -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; @@ -30,11 +32,23 @@ private static void WriteValues(T[] array, Stream stream, Type elementType, V stream.WriteObject(value, elementType, elementSerializer, preserveObjectReferences, session); } } - private static void ReadValues(int length, Stream stream, DeserializerSession session, T[] array) + private static void ReadValues(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; } } @@ -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; };