diff --git a/.gitignore b/.gitignore index c5a1b2d..f48ec73 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,7 @@ *.user *.userosscache *.sln.docstates - +.ionide/** # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs diff --git a/src/Hyperion/SerializerFactories/ArraySerializerFactory.cs b/src/Hyperion/SerializerFactories/ArraySerializerFactory.cs index a4ac76a..4067ba7 100644 --- a/src/Hyperion/SerializerFactories/ArraySerializerFactory.cs +++ b/src/Hyperion/SerializerFactories/ArraySerializerFactory.cs @@ -21,7 +21,7 @@ namespace Hyperion.SerializerFactories public override bool CanDeserialize(Serializer serializer, Type type) => CanSerialize(serializer, type); - private static void WriteValues(T[] array, Stream stream, Type elementType, ValueSerializer elementSerializer, SerializerSession session) + private static void WriteValues(Array array, Stream stream, Type elementType, ValueSerializer elementSerializer, SerializerSession session) { Int32Serializer.WriteValueImpl(stream, array.Length, session); var preserveObjectReferences = session.Serializer.Options.PreserveObjectReferences; @@ -30,12 +30,12 @@ namespace Hyperion.SerializerFactories stream.WriteObject(value, elementType, elementSerializer, preserveObjectReferences, session); } } - private static void ReadValues(int length, Stream stream, DeserializerSession session, T[] array) + private static void ReadValues(int length, Stream stream, DeserializerSession session, Array array) { for (var i = 0; i < length; i++) { - var value = (T)stream.ReadObject(session); - array[i] = value; + var value = stream.ReadObject(session); + array.SetValue(value, i); } } @@ -57,7 +57,7 @@ namespace Hyperion.SerializerFactories session.TrackDeserializedObject(array); } - ReadValues(length, stream, session, (dynamic)array); + ReadValues(length, stream, session, array); return array; }; @@ -68,7 +68,7 @@ namespace Hyperion.SerializerFactories session.TrackSerializedObject(arr); } - WriteValues((dynamic)arr, stream, elementType, elementSerializer, session); + WriteValues((Array)arr, stream, elementType, elementSerializer, session); }; arraySerializer.Initialize(reader, writer); typeMapping.TryAdd(type, arraySerializer); diff --git a/src/Hyperion/ValueSerializers/ConsistentArraySerializer.cs b/src/Hyperion/ValueSerializers/ConsistentArraySerializer.cs index ec07500..c803d7c 100644 --- a/src/Hyperion/ValueSerializers/ConsistentArraySerializer.cs +++ b/src/Hyperion/ValueSerializers/ConsistentArraySerializer.cs @@ -71,15 +71,16 @@ namespace Hyperion.ValueSerializers var elementSerializer = session.Serializer.GetSerializerByType(elementType); elementSerializer.WriteManifest(stream, session); //write array element type // ReSharper disable once PossibleNullReferenceException - WriteValues((dynamic)value, stream,elementSerializer,session); + WriteValues((Array)value, stream,elementSerializer,session); } - private static void WriteValues(T[] array, Stream stream, ValueSerializer elementSerializer, SerializerSession session) + private static void WriteValues(Array array, Stream stream, ValueSerializer elementSerializer, SerializerSession session) { + var tp = array.GetType(); Int32Serializer.WriteValueImpl(stream,array.Length,session); - if (typeof(T).IsFixedSizeType()) + if (tp.IsFixedSizeType()) { - var size = typeof(T).GetTypeSize(); + var size = tp.GetTypeSize(); var result = new byte[array.Length * size]; Buffer.BlockCopy(array, 0, result, 0, result.Length); stream.Write(result);