Skip to content

Commit b6a4f25

Browse files
Merge pull request #164 from akkadotnet/dev
v0.9.14 Release
2 parents 457a5e7 + 3ea2f72 commit b6a4f25

File tree

6 files changed

+62
-9
lines changed

6 files changed

+62
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
A high performance polymorphic serializer for the .NET framework.
66

7-
Current status: **BETA** (v0.9.12).
7+
Current status: **BETA** (v0.9.14).
88

99
## License
1010
Licensed under Apache 2.0, see [LICENSE](LICENSE) for the full text.

RELEASE_NOTES.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
### 0.9.13 February 09 2020 ####
1+
### 0.9.14 February 13 2020 ####
22

3-
* [Added support for serializing and deserializing `IDictionary<TKey, TValue>`](https://github.com/akkadotnet/Hyperion/pull/156)
3+
* [Added support for serializing and deserializing `IDictionary<TKey, TValue>` with private and protected default constructor] (https://github.com/akkadotnet/Hyperion/pull/162)

src/Hyperion.Tests/GenericDictionarySerializerTests.cs

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,41 @@ namespace Hyperion.Tests
99
public class GenericDictionarySerializerTests : TestBase
1010
{
1111
[Fact]
12-
public void CanSerializeDictionary()
12+
public void CanSerializeDictionaryWithPublicDefaultConstructor()
1313
{
1414
var customDict = new CustomDictionary<string, int>(new Dictionary<string, int>()
1515
{
16-
["key"] = 1
16+
["key1"] = 1,
17+
["key2"] = 2,
18+
["key3"] = 2,
1719
});
1820
SerializeAndAssertEquivalent(customDict);
1921
}
20-
22+
23+
[Fact]
24+
public void CanSerializeDictionaryWithPrivateDefaultConstructor()
25+
{
26+
var customDict = new PrivateCustomDictionary<string, int>(new Dictionary<string, int>()
27+
{
28+
["key1"] = 1,
29+
["key2"] = 2,
30+
["key3"] = 2,
31+
});
32+
SerializeAndAssertEquivalent(customDict);
33+
}
34+
35+
[Fact]
36+
public void CanSerializeDictionaryWithProtectedDefaultConstructor()
37+
{
38+
var customDict = new ProtectedCustomDictionary<string, int>(new Dictionary<string, int>()
39+
{
40+
["key1"] = 1,
41+
["key2"] = 2,
42+
["key3"] = 2,
43+
});
44+
SerializeAndAssertEquivalent(customDict);
45+
}
46+
2147
private void SerializeAndAssertEquivalent<T>(T expected)
2248
{
2349
Serialize(expected);
@@ -27,6 +53,24 @@ private void SerializeAndAssertEquivalent<T>(T expected)
2753
AssertMemoryStreamConsumed();
2854
}
2955

56+
class PrivateCustomDictionary<TKey, TValue> : CustomDictionary<TKey, TValue>
57+
{
58+
private PrivateCustomDictionary() : base(new Dictionary<TKey, TValue>())
59+
{ }
60+
61+
public PrivateCustomDictionary(Dictionary<TKey, TValue> dict) : base(new Dictionary<TKey, TValue>())
62+
{ }
63+
}
64+
65+
class ProtectedCustomDictionary<TKey, TValue> : CustomDictionary<TKey, TValue>
66+
{
67+
protected ProtectedCustomDictionary() : base(new Dictionary<TKey, TValue>())
68+
{ }
69+
70+
public ProtectedCustomDictionary(Dictionary<TKey, TValue> dict) : base(new Dictionary<TKey, TValue>())
71+
{ }
72+
}
73+
3074
/// <summary>
3175
/// Just a custom class wrapper for another <see cref="IDictionary{TKey,TValue}"/>
3276
/// </summary>

src/Hyperion.Tests/Hyperion.Tests.csproj

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

1212
<ItemGroup>
13-
<PackageReference Include="FluentAssertions" Version="5.10.0" />
13+
<PackageReference Include="FluentAssertions" Version="5.10.2" />
1414
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
1515
<PackageReference Include="System.Collections.Immutable" Version="1.7.0" />
1616
<PackageReference Include="xunit" Version="$(XunitVersion)" />

src/Hyperion/Hyperion.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111

1212
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.6' ">
1313
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.7.0" />
14-
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
1514
</ItemGroup>
1615

1716
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
1817
<PackageReference Include="System.Runtime" Version="4.3.1" />
18+
</ItemGroup>
19+
20+
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' Or '$(TargetFramework)' == 'netstandard1.6' ">
1921
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
2022
</ItemGroup>
2123

src/Hyperion/SerializerFactories/DictionarySerializerFactory.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,14 @@ public override ValueSerializer BuildSerializer(Serializer serializer, Type type
4444

4545
ObjectReader reader = (stream, session) =>
4646
{
47-
var instance = Activator.CreateInstance(type); // IDictionary<TKey, TValue>
47+
object instance;
48+
try
49+
{
50+
instance = Activator.CreateInstance(type, true); // IDictionary<TKey, TValue>
51+
} catch(Exception) {
52+
instance = Activator.CreateInstance(type); // IDictionary<TKey, TValue>
53+
}
54+
4855
if (preserveObjectReferences)
4956
{
5057
session.TrackDeserializedObject(instance);

0 commit comments

Comments
 (0)