Skip to content

Commit

Permalink
Merge pull request #179 from akkadotnet/dev
Browse files Browse the repository at this point in the history
v0.9.16 Release
  • Loading branch information
Aaronontheweb authored Jun 17, 2020
2 parents 0f2044d + e5d4900 commit 204e3c6
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 24 deletions.
9 changes: 6 additions & 3 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### 0.9.15 February 27 2020 ####

* [Fix `Type.GetGenericTypeDefinition()` interface error](https://github.com/akkadotnet/Hyperion/pull/166)
### 0.9.16 June 17 2020 ####
* [Bump Microsoft.NET.Test.Sdk from 16.5.0 to 16.6.1](https://github.com/akkadotnet/Hyperion/pull/174)
* [Add deserialization support for ReadOnlyDictionary](https://github.com/akkadotnet/Hyperion/pull/177)
* [Bump FluentAssertions from 5.10.2 to 5.10.3](https://github.com/akkadotnet/Hyperion/pull/171)
* [Bump System.Collections.Immutable from 1.7.0 to 1.7.1](https://github.com/akkadotnet/Hyperion/pull/175)
* [Bump BenchmarkDotNet from 0.12.0 to 0.12.1](https://github.com/akkadotnet/Hyperion/pull/172)
2 changes: 1 addition & 1 deletion src/Hyperion.Benchmarks/Hyperion.Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.12.0" />
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Update="FSharp.Core" Version="4.7.0" />
<PackageReference Update="FSharp.Core" Version="4.7.2" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions src/Hyperion.Tests/Hyperion.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.10.2" />
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="1.7.0" />
<PackageReference Include="System.Collections.Immutable" Version="1.7.1" />
<PackageReference Include="xunit" Version="$(XunitVersion)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitVersion)" />
</ItemGroup>
Expand Down
57 changes: 57 additions & 0 deletions src/Hyperion.Tests/ImmutableCollectionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

using System.Collections.Generic;
using System.Collections.Immutable;
using System.Collections.ObjectModel;
using System.Linq;
using Xunit;

Expand Down Expand Up @@ -150,6 +151,62 @@ public void CanSerializeImmutableDictionary()
Assert.Equal(expected.ToList(), actual.ToList());
}

[Fact]
public void CanSerializeIReadOnlyDictionary()
{
var dict = ImmutableDictionary.CreateRange(new Dictionary<string, Something>
{
["a1"] = new Something
{
BoolProp = true,
Else = new Else
{
Name = "Yoho"
},
Int32Prop = 999,
StringProp = "Yesbox!"
},
["a2"] = new Something(),
["a3"] = new Something(),
["a4"] = null
});

var expected = (IReadOnlyDictionary<string, Something>)dict;

Serialize(expected);
Reset();
var actual = Deserialize<IReadOnlyDictionary<string, Something>>();
Assert.Equal(expected.ToList(), actual.ToList());
}

[Fact]
public void CanSerializeReadOnlyDictionary()
{
var dict = new Dictionary<string, Something>
{
["a1"] = new Something
{
BoolProp = true,
Else = new Else
{
Name = "Yoho"
},
Int32Prop = 999,
StringProp = "Yesbox!"
},
["a2"] = new Something(),
["a3"] = new Something(),
["a4"] = null
};

var expected = new ReadOnlyDictionary<string, Something>(dict);

Serialize(expected);
Reset();
var actual = Deserialize<ReadOnlyDictionary<string, Something>>();
Assert.Equal(expected.ToList(), actual.ToList());
}

[Fact]
public void CanSerializeImmutableQueue()
{
Expand Down
54 changes: 40 additions & 14 deletions src/Hyperion/SerializerFactories/DictionarySerializerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reflection;
using Hyperion.Extensions;
Expand Down Expand Up @@ -45,6 +46,44 @@ public override ValueSerializer BuildSerializer(Serializer serializer, Type type
ObjectReader reader = (stream, session) =>
{
object instance;

void ReadDictionaryKeyValuePairs(object dictionaryInstance)
{
var count = stream.ReadInt32(session);
for (var i = 0; i < count; i++)
{
var entry = stream.ReadObject(session); // KeyValuePair<TKey, TValue>

// Get entry.Key and entry.Value
var key = dictionaryTypes.KeyValuePairType.GetProperty(nameof(KeyValuePair<object, object>.Key)).GetValue(entry, null);
var value = dictionaryTypes.KeyValuePairType.GetProperty(nameof(KeyValuePair<object, object>.Value)).GetValue(entry, null);

// Same as: instance.Add(key, value)
dictionaryTypes.DictionaryInterfaceType
.GetMethod(nameof(IDictionary<object, object>.Add), new[] { dictionaryTypes.KeyType, dictionaryTypes.ValueType })
.Invoke(dictionaryInstance, new[] { key, value });
}
}

#region Special case for ReadOnlyDictionary
// Special case for ReadOnlyDictionary since ReadOnlyDictionary
// does not have a parameterless constructor
var genericReadOnlyDictionary = typeof(ReadOnlyDictionary<,>);
var readOnlyDictionaryType =
genericReadOnlyDictionary.MakeGenericType(dictionaryTypes.KeyType, dictionaryTypes.ValueType);
if (type.Equals(readOnlyDictionaryType))
{
var genericDictionary = typeof(Dictionary<,>);
var genericDictionaryType = genericDictionary.MakeGenericType(dictionaryTypes.KeyType, dictionaryTypes.ValueType);
var dictionary = Activator.CreateInstance(genericDictionaryType); // normal dictionary

ReadDictionaryKeyValuePairs(dictionary);
instance = Activator.CreateInstance(type, dictionary); // IDictionary<TKey, TValue>
if (preserveObjectReferences) session.TrackDeserializedObject(instance);
return instance;
}
#endregion

try
{
instance = Activator.CreateInstance(type, true); // IDictionary<TKey, TValue>
Expand All @@ -56,20 +95,7 @@ public override ValueSerializer BuildSerializer(Serializer serializer, Type type
{
session.TrackDeserializedObject(instance);
}
var count = stream.ReadInt32(session);
for (var i = 0; i < count; i++)
{
var entry = stream.ReadObject(session); // KeyValuePair<TKey, TValue>

// Get entry.Key and entry.Value
var key = dictionaryTypes.KeyValuePairType.GetProperty(nameof(KeyValuePair<object, object>.Key)).GetValue(entry, null);
var value = dictionaryTypes.KeyValuePairType.GetProperty(nameof(KeyValuePair<object, object>.Value)).GetValue(entry, null);

// Same as: instance.Add(key, value)
dictionaryTypes.DictionaryInterfaceType
.GetMethod(nameof(IDictionary<object, object>.Add), new []{ dictionaryTypes.KeyType, dictionaryTypes.ValueType })
.Invoke(instance, new [] { key, value });
}
ReadDictionaryKeyValuePairs(instance);

return instance;
};
Expand Down
10 changes: 7 additions & 3 deletions src/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@
<PropertyGroup>
<Copyright>Copyright © 2016-2017 Akka.NET Team</Copyright>
<Authors>Akka.NET Team</Authors>
<VersionPrefix>0.9.15</VersionPrefix>
<PackageReleaseNotes>[Fix `Type.GetGenericTypeDefinition()` interface error](https://github.com/akkadotnet/Hyperion/pull/166)</PackageReleaseNotes>
<VersionPrefix>0.9.16</VersionPrefix>
<PackageReleaseNotes>[Bump Microsoft.NET.Test.Sdk from 16.5.0 to 16.6.1](https://github.com/akkadotnet/Hyperion/pull/174)
[Add deserialization support for ReadOnlyDictionary](https://github.com/akkadotnet/Hyperion/pull/177)
[Bump FluentAssertions from 5.10.2 to 5.10.3](https://github.com/akkadotnet/Hyperion/pull/171)
[Bump System.Collections.Immutable from 1.7.0 to 1.7.1](https://github.com/akkadotnet/Hyperion/pull/175)
[Bump BenchmarkDotNet from 0.12.0 to 0.12.1](https://github.com/akkadotnet/Hyperion/pull/172)</PackageReleaseNotes>
<PackageIconUrl>http://getakka.net/images/akkalogo.png</PackageIconUrl>
<PackageProjectUrl>https://github.com/akkadotnet/Hyperion</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/akkadotnet/Hyperion/blob/master/LICENSE</PackageLicenseUrl>
<NoWarn>$(NoWarn);CS1591</NoWarn>
</PropertyGroup>
<PropertyGroup>
<XunitVersion>2.4.1</XunitVersion>
<TestSdkVersion>16.5.0</TestSdkVersion>
<TestSdkVersion>16.6.1</TestSdkVersion>
<NBenchVersion>1.2.2</NBenchVersion>
</PropertyGroup>
</Project>

0 comments on commit 204e3c6

Please sign in to comment.