Skip to content

Commit

Permalink
Merge pull request #22 from akkadotnet/dev
Browse files Browse the repository at this point in the history
Hyperion v0.9.2 Release
  • Loading branch information
Aaronontheweb authored Jan 6, 2017
2 parents 6715f71 + 14b638e commit 80cf211
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 18 deletions.
Binary file modified .nuget/NuGet.exe
Binary file not shown.
6 changes: 3 additions & 3 deletions Hyperion.FSharpTestTypes/AssemblyInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ open System.Runtime.InteropServices
[<assembly: AssemblyCompanyAttribute("Akka.NET Team")>]
[<assembly: ComVisibleAttribute(false)>]
[<assembly: CLSCompliantAttribute(true)>]
[<assembly: AssemblyVersionAttribute("0.9.0.0")>]
[<assembly: AssemblyFileVersionAttribute("0.9.0.0")>]
[<assembly: AssemblyVersionAttribute("0.9.1.0")>]
[<assembly: AssemblyFileVersionAttribute("0.9.1.0")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] Version = "0.9.0.0"
let [<Literal>] Version = "0.9.1.0"
63 changes: 63 additions & 0 deletions Hyperion.Tests/CollectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#endregion

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Dynamic;
Expand Down Expand Up @@ -318,5 +319,67 @@ public void Issue18()

Assert.True(msg.SequenceEqual(deserialized));
}

#region test classes

public class CustomAdd : IEnumerable<int>
{
public IImmutableList<int> Inner { get; }
public int Count => Inner.Count;

public CustomAdd(IImmutableList<int> inner)
{
this.Inner = inner;
}

public CustomAdd Add(int item) => new CustomAdd(Inner.Add(item));

public IEnumerator<int> GetEnumerator() => Inner.GetEnumerator();

IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}

public class CustomAddRange : IEnumerable<int>
{
public IImmutableList<int> Inner { get; }
public int Count => Inner.Count;

public CustomAddRange(IImmutableList<int> inner)
{
this.Inner = inner;
}

public CustomAddRange AddRange(string newLabel, int[] items) => new CustomAddRange(Inner.AddRange(items));

public IEnumerator<int> GetEnumerator() => Inner.GetEnumerator();

IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}

#endregion

[Fact]
public void CanSerializeCustomEnumerableWithNonStandardAddSignature()
{
var init = new CustomAdd(ImmutableList<int>.Empty);
var expected = init.Add(1).Add(2);

Serialize(expected);
Reset();
var actual = Deserialize<CustomAdd>();
Assert.True(expected.SequenceEqual(actual));
}

[Fact]
public void CanSerializeCustomEnumerableWithNonStandardAddRangeSignature()
{
var init = new CustomAddRange(ImmutableList<int>.Empty);
var expected = init.AddRange("label", new []{ 1, 2, 3 });

Serialize(expected);
Reset();
var actual = Deserialize<CustomAddRange>();
Assert.True(expected.SequenceEqual(actual));
}
}
}
12 changes: 7 additions & 5 deletions Hyperion/SerializerFactories/ArraySerializerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Runtime.ExceptionServices;
using Hyperion.Extensions;
using Hyperion.ValueSerializers;

Expand All @@ -21,7 +24,7 @@ public class ArraySerializerFactory : ValueSerializerFactory

public override bool CanDeserialize(Serializer serializer, Type type) => CanSerialize(serializer, type);

private static void WriteValues<T>(T[] array,Stream stream,Type elementType, ValueSerializer elementSerializer, SerializerSession session)
private static void WriteValues<T>(T[] array, Stream stream, Type elementType, ValueSerializer elementSerializer, SerializerSession session)
{
Int32Serializer.WriteValueImpl(stream, array.Length, session);
var preserveObjectReferences = session.Serializer.Options.PreserveObjectReferences;
Expand All @@ -43,7 +46,7 @@ public override ValueSerializer BuildSerializer(Serializer serializer, Type type
ConcurrentDictionary<Type, ValueSerializer> typeMapping)
{
var arraySerializer = new ObjectSerializer(type);

var elementType = type.GetElementType();
var elementSerializer = serializer.GetSerializerByType(elementType);
var preserveObjectReferences = serializer.Options.PreserveObjectReferences;
Expand All @@ -57,7 +60,7 @@ public override ValueSerializer BuildSerializer(Serializer serializer, Type type
session.TrackDeserializedObject(array);
}

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

return array;
};
Expand All @@ -68,8 +71,7 @@ public override ValueSerializer BuildSerializer(Serializer serializer, Type type
session.TrackSerializedObject(arr);
}

WriteValues((dynamic) arr, stream, elementType, elementSerializer, session);

WriteValues((dynamic)arr, stream, elementType, elementSerializer, session);
};
arraySerializer.Initialize(reader, writer);
typeMapping.TryAdd(type, arraySerializer);
Expand Down
29 changes: 21 additions & 8 deletions Hyperion/SerializerFactories/EnumerableSerializerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,35 @@ public override bool CanSerialize(Serializer serializer, Type type)
{
//TODO: check for constructor with IEnumerable<T> param

if (!type.GetTypeInfo().GetMethods().Any(m => m.Name == "AddRange" || m.Name == "Add"))
var countProperty = type.GetTypeInfo().GetProperty("Count");
if (countProperty == null || countProperty.PropertyType != typeof(int))
return false;

if (type.GetTypeInfo().GetProperty("Count") == null)
if (!type.GetTypeInfo().GetMethods().Any(IsAddMethod))
return false;

var isGenericEnumerable = GetEnumerableType(type) != null;
if (isGenericEnumerable)
return true;

if (typeof (ICollection).GetTypeInfo().IsAssignableFrom(type))
if (typeof(ICollection).GetTypeInfo().IsAssignableFrom(type))
return true;

return false;
}

private static bool IsAddMethod(MethodInfo methodInfo) =>
(methodInfo.Name == "AddRange" || methodInfo.Name == "Add")
&& (methodInfo.ReturnType == typeof(void) || methodInfo.ReturnType == typeof(bool)) // sets return bool on Add
&& !methodInfo.IsStatic
&& HasValidParameters(methodInfo);

private static bool HasValidParameters(MethodInfo methodInfo)
{
var parameters = methodInfo.GetParameters();
return parameters.Length == 1;
}

public override bool CanDeserialize(Serializer serializer, Type type)
{
return CanSerialize(serializer, type);
Expand All @@ -50,7 +63,7 @@ private static Type GetEnumerableType(Type type)
return type
.GetTypeInfo()
.GetInterfaces()
.Where(intType => intType.GetTypeInfo().IsGenericType && intType.GetTypeInfo().GetGenericTypeDefinition() == typeof (IEnumerable<>))
.Where(intType => intType.GetTypeInfo().IsGenericType && intType.GetTypeInfo().GetGenericTypeDefinition() == typeof(IEnumerable<>))
.Select(intType => intType.GetTypeInfo().GetGenericArguments()[0])
.FirstOrDefault();
}
Expand All @@ -62,7 +75,7 @@ public override ValueSerializer BuildSerializer(Serializer serializer, Type type
typeMapping.TryAdd(type, x);
var preserveObjectReferences = serializer.Options.PreserveObjectReferences;

var elementType = GetEnumerableType(type) ?? typeof (object);
var elementType = GetEnumerableType(type) ?? typeof(object);
var elementSerializer = serializer.GetSerializerByType(elementType);

var countProperty = type.GetTypeInfo().GetProperty("Count");
Expand All @@ -81,7 +94,7 @@ public override ValueSerializer BuildSerializer(Serializer serializer, Type type
}

var count = stream.ReadInt32(session);

if (addRange != null)
{
var items = Array.CreateInstance(elementType, count);
Expand All @@ -92,7 +105,7 @@ public override ValueSerializer BuildSerializer(Serializer serializer, Type type
}
//HACK: this needs to be fixed, codegenerated or whatever

addRange.Invoke(instance, new object[] {items});
addRange.Invoke(instance, new object[] { items });
return instance;
}
if (add != null)
Expand All @@ -114,7 +127,7 @@ public override ValueSerializer BuildSerializer(Serializer serializer, Type type
{
session.TrackSerializedObject(o);
}
Int32Serializer.WriteValueImpl(stream, countGetter(o),session);
Int32Serializer.WriteValueImpl(stream, countGetter(o), session);
var enumerable = o as IEnumerable;
// ReSharper disable once PossibleNullReferenceException
foreach (var value in enumerable)
Expand Down
5 changes: 5 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### 0.9.2 January 05 2017
Includes bug fixes for immutable data structures and lists.

See the full set of changes here: [Hyperion 0.9.2 Milestone](https://github.com/akkadotnet/Hyperion/milestone/2)

### 0.9.1 January 02 2017
Includes bug fixes for numerous data structures as well as improved build chain and tools standardization.

Expand Down
4 changes: 2 additions & 2 deletions SharedAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
[assembly: AssemblyCompanyAttribute("Akka.NET Team")]
[assembly: AssemblyCopyrightAttribute("Copyright 2016 Akka.NET Team")]
[assembly: AssemblyTrademarkAttribute("")]
[assembly: AssemblyVersionAttribute("0.9.0.0")]
[assembly: AssemblyFileVersionAttribute("0.9.0.0")]
[assembly: AssemblyVersionAttribute("0.9.1.0")]
[assembly: AssemblyFileVersionAttribute("0.9.1.0")]

0 comments on commit 80cf211

Please sign in to comment.