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 8abef01..235f6c6 100644 --- a/src/Hyperion/SerializerFactories/ArraySerializerFactory.cs +++ b/src/Hyperion/SerializerFactories/ArraySerializerFactory.cs @@ -71,8 +71,7 @@ namespace Hyperion.SerializerFactories session.TrackSerializedObject(arr); } - // This janky way of converting array to Array is done to get around the problem of ValueType arrays - WriteValues(((IEnumerable)arr).Cast().ToArray(), stream, elementType, elementSerializer, session); + WriteValues((Array)arr, stream, elementType, elementSerializer, session); }; arraySerializer.Initialize(reader, writer); diff --git a/src/Hyperion/ValueSerializers/ConsistentArraySerializer.cs b/src/Hyperion/ValueSerializers/ConsistentArraySerializer.cs index 6ce232c..a1a75d6 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);