Skip to content

Commit 204e3c6

Browse files
Merge pull request #179 from akkadotnet/dev
v0.9.16 Release
2 parents 0f2044d + e5d4900 commit 204e3c6

File tree

7 files changed

+114
-24
lines changed

7 files changed

+114
-24
lines changed

RELEASE_NOTES.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
### 0.9.15 February 27 2020 ####
2-
3-
* [Fix `Type.GetGenericTypeDefinition()` interface error](https://github.com/akkadotnet/Hyperion/pull/166)
1+
### 0.9.16 June 17 2020 ####
2+
* [Bump Microsoft.NET.Test.Sdk from 16.5.0 to 16.6.1](https://github.com/akkadotnet/Hyperion/pull/174)
3+
* [Add deserialization support for ReadOnlyDictionary](https://github.com/akkadotnet/Hyperion/pull/177)
4+
* [Bump FluentAssertions from 5.10.2 to 5.10.3](https://github.com/akkadotnet/Hyperion/pull/171)
5+
* [Bump System.Collections.Immutable from 1.7.0 to 1.7.1](https://github.com/akkadotnet/Hyperion/pull/175)
6+
* [Bump BenchmarkDotNet from 0.12.0 to 0.12.1](https://github.com/akkadotnet/Hyperion/pull/172)

src/Hyperion.Benchmarks/Hyperion.Benchmarks.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="BenchmarkDotNet" Version="0.12.0" />
10+
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
1111
</ItemGroup>
1212

1313
<ItemGroup>

src/Hyperion.Tests.FSharpData/Hyperion.Tests.FSharpData.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</ItemGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Update="FSharp.Core" Version="4.7.0" />
12+
<PackageReference Update="FSharp.Core" Version="4.7.2" />
1313
</ItemGroup>
1414

1515
</Project>

src/Hyperion.Tests/Hyperion.Tests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
</PropertyGroup>
1111

1212
<ItemGroup>
13-
<PackageReference Include="FluentAssertions" Version="5.10.2" />
13+
<PackageReference Include="FluentAssertions" Version="5.10.3" />
1414
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
15-
<PackageReference Include="System.Collections.Immutable" Version="1.7.0" />
15+
<PackageReference Include="System.Collections.Immutable" Version="1.7.1" />
1616
<PackageReference Include="xunit" Version="$(XunitVersion)" />
1717
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitVersion)" />
1818
</ItemGroup>

src/Hyperion.Tests/ImmutableCollectionsTests.cs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
using System.Collections.Generic;
1111
using System.Collections.Immutable;
12+
using System.Collections.ObjectModel;
1213
using System.Linq;
1314
using Xunit;
1415

@@ -150,6 +151,62 @@ public void CanSerializeImmutableDictionary()
150151
Assert.Equal(expected.ToList(), actual.ToList());
151152
}
152153

154+
[Fact]
155+
public void CanSerializeIReadOnlyDictionary()
156+
{
157+
var dict = ImmutableDictionary.CreateRange(new Dictionary<string, Something>
158+
{
159+
["a1"] = new Something
160+
{
161+
BoolProp = true,
162+
Else = new Else
163+
{
164+
Name = "Yoho"
165+
},
166+
Int32Prop = 999,
167+
StringProp = "Yesbox!"
168+
},
169+
["a2"] = new Something(),
170+
["a3"] = new Something(),
171+
["a4"] = null
172+
});
173+
174+
var expected = (IReadOnlyDictionary<string, Something>)dict;
175+
176+
Serialize(expected);
177+
Reset();
178+
var actual = Deserialize<IReadOnlyDictionary<string, Something>>();
179+
Assert.Equal(expected.ToList(), actual.ToList());
180+
}
181+
182+
[Fact]
183+
public void CanSerializeReadOnlyDictionary()
184+
{
185+
var dict = new Dictionary<string, Something>
186+
{
187+
["a1"] = new Something
188+
{
189+
BoolProp = true,
190+
Else = new Else
191+
{
192+
Name = "Yoho"
193+
},
194+
Int32Prop = 999,
195+
StringProp = "Yesbox!"
196+
},
197+
["a2"] = new Something(),
198+
["a3"] = new Something(),
199+
["a4"] = null
200+
};
201+
202+
var expected = new ReadOnlyDictionary<string, Something>(dict);
203+
204+
Serialize(expected);
205+
Reset();
206+
var actual = Deserialize<ReadOnlyDictionary<string, Something>>();
207+
Assert.Equal(expected.ToList(), actual.ToList());
208+
}
209+
153210
[Fact]
154211
public void CanSerializeImmutableQueue()
155212
{

src/Hyperion/SerializerFactories/DictionarySerializerFactory.cs

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using System.Collections;
1212
using System.Collections.Concurrent;
1313
using System.Collections.Generic;
14+
using System.Collections.ObjectModel;
1415
using System.Linq;
1516
using System.Reflection;
1617
using Hyperion.Extensions;
@@ -45,6 +46,44 @@ public override ValueSerializer BuildSerializer(Serializer serializer, Type type
4546
ObjectReader reader = (stream, session) =>
4647
{
4748
object instance;
49+
50+
void ReadDictionaryKeyValuePairs(object dictionaryInstance)
51+
{
52+
var count = stream.ReadInt32(session);
53+
for (var i = 0; i < count; i++)
54+
{
55+
var entry = stream.ReadObject(session); // KeyValuePair<TKey, TValue>
56+
57+
// Get entry.Key and entry.Value
58+
var key = dictionaryTypes.KeyValuePairType.GetProperty(nameof(KeyValuePair<object, object>.Key)).GetValue(entry, null);
59+
var value = dictionaryTypes.KeyValuePairType.GetProperty(nameof(KeyValuePair<object, object>.Value)).GetValue(entry, null);
60+
61+
// Same as: instance.Add(key, value)
62+
dictionaryTypes.DictionaryInterfaceType
63+
.GetMethod(nameof(IDictionary<object, object>.Add), new[] { dictionaryTypes.KeyType, dictionaryTypes.ValueType })
64+
.Invoke(dictionaryInstance, new[] { key, value });
65+
}
66+
}
67+
68+
#region Special case for ReadOnlyDictionary
69+
// Special case for ReadOnlyDictionary since ReadOnlyDictionary
70+
// does not have a parameterless constructor
71+
var genericReadOnlyDictionary = typeof(ReadOnlyDictionary<,>);
72+
var readOnlyDictionaryType =
73+
genericReadOnlyDictionary.MakeGenericType(dictionaryTypes.KeyType, dictionaryTypes.ValueType);
74+
if (type.Equals(readOnlyDictionaryType))
75+
{
76+
var genericDictionary = typeof(Dictionary<,>);
77+
var genericDictionaryType = genericDictionary.MakeGenericType(dictionaryTypes.KeyType, dictionaryTypes.ValueType);
78+
var dictionary = Activator.CreateInstance(genericDictionaryType); // normal dictionary
79+
80+
ReadDictionaryKeyValuePairs(dictionary);
81+
instance = Activator.CreateInstance(type, dictionary); // IDictionary<TKey, TValue>
82+
if (preserveObjectReferences) session.TrackDeserializedObject(instance);
83+
return instance;
84+
}
85+
#endregion
86+
4887
try
4988
{
5089
instance = Activator.CreateInstance(type, true); // IDictionary<TKey, TValue>
@@ -56,20 +95,7 @@ public override ValueSerializer BuildSerializer(Serializer serializer, Type type
5695
{
5796
session.TrackDeserializedObject(instance);
5897
}
59-
var count = stream.ReadInt32(session);
60-
for (var i = 0; i < count; i++)
61-
{
62-
var entry = stream.ReadObject(session); // KeyValuePair<TKey, TValue>
63-
64-
// Get entry.Key and entry.Value
65-
var key = dictionaryTypes.KeyValuePairType.GetProperty(nameof(KeyValuePair<object, object>.Key)).GetValue(entry, null);
66-
var value = dictionaryTypes.KeyValuePairType.GetProperty(nameof(KeyValuePair<object, object>.Value)).GetValue(entry, null);
67-
68-
// Same as: instance.Add(key, value)
69-
dictionaryTypes.DictionaryInterfaceType
70-
.GetMethod(nameof(IDictionary<object, object>.Add), new []{ dictionaryTypes.KeyType, dictionaryTypes.ValueType })
71-
.Invoke(instance, new [] { key, value });
72-
}
98+
ReadDictionaryKeyValuePairs(instance);
7399

74100
return instance;
75101
};

src/common.props

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,20 @@
22
<PropertyGroup>
33
<Copyright>Copyright © 2016-2017 Akka.NET Team</Copyright>
44
<Authors>Akka.NET Team</Authors>
5-
<VersionPrefix>0.9.15</VersionPrefix>
6-
<PackageReleaseNotes>[Fix `Type.GetGenericTypeDefinition()` interface error](https://github.com/akkadotnet/Hyperion/pull/166)</PackageReleaseNotes>
5+
<VersionPrefix>0.9.16</VersionPrefix>
6+
<PackageReleaseNotes>[Bump Microsoft.NET.Test.Sdk from 16.5.0 to 16.6.1](https://github.com/akkadotnet/Hyperion/pull/174)
7+
[Add deserialization support for ReadOnlyDictionary](https://github.com/akkadotnet/Hyperion/pull/177)
8+
[Bump FluentAssertions from 5.10.2 to 5.10.3](https://github.com/akkadotnet/Hyperion/pull/171)
9+
[Bump System.Collections.Immutable from 1.7.0 to 1.7.1](https://github.com/akkadotnet/Hyperion/pull/175)
10+
[Bump BenchmarkDotNet from 0.12.0 to 0.12.1](https://github.com/akkadotnet/Hyperion/pull/172)</PackageReleaseNotes>
711
<PackageIconUrl>http://getakka.net/images/akkalogo.png</PackageIconUrl>
812
<PackageProjectUrl>https://github.com/akkadotnet/Hyperion</PackageProjectUrl>
913
<PackageLicenseUrl>https://github.com/akkadotnet/Hyperion/blob/master/LICENSE</PackageLicenseUrl>
1014
<NoWarn>$(NoWarn);CS1591</NoWarn>
1115
</PropertyGroup>
1216
<PropertyGroup>
1317
<XunitVersion>2.4.1</XunitVersion>
14-
<TestSdkVersion>16.5.0</TestSdkVersion>
18+
<TestSdkVersion>16.6.1</TestSdkVersion>
1519
<NBenchVersion>1.2.2</NBenchVersion>
1620
</PropertyGroup>
1721
</Project>

0 commit comments

Comments
 (0)