Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.9.14 Release #164

Merged
merged 3 commits into from
Feb 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

A high performance polymorphic serializer for the .NET framework.

Current status: **BETA** (v0.9.12).
Current status: **BETA** (v0.9.14).

## License
Licensed under Apache 2.0, see [LICENSE](LICENSE) for the full text.
Expand Down
4 changes: 2 additions & 2 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
### 0.9.13 February 09 2020 ####
### 0.9.14 February 13 2020 ####

* [Added support for serializing and deserializing `IDictionary<TKey, TValue>`](https://github.com/akkadotnet/Hyperion/pull/156)
* [Added support for serializing and deserializing `IDictionary<TKey, TValue>` with private and protected default constructor] (https://github.com/akkadotnet/Hyperion/pull/162)
50 changes: 47 additions & 3 deletions src/Hyperion.Tests/GenericDictionarySerializerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,41 @@ namespace Hyperion.Tests
public class GenericDictionarySerializerTests : TestBase
{
[Fact]
public void CanSerializeDictionary()
public void CanSerializeDictionaryWithPublicDefaultConstructor()
{
var customDict = new CustomDictionary<string, int>(new Dictionary<string, int>()
{
["key"] = 1
["key1"] = 1,
["key2"] = 2,
["key3"] = 2,
});
SerializeAndAssertEquivalent(customDict);
}


[Fact]
public void CanSerializeDictionaryWithPrivateDefaultConstructor()
{
var customDict = new PrivateCustomDictionary<string, int>(new Dictionary<string, int>()
{
["key1"] = 1,
["key2"] = 2,
["key3"] = 2,
});
SerializeAndAssertEquivalent(customDict);
}

[Fact]
public void CanSerializeDictionaryWithProtectedDefaultConstructor()
{
var customDict = new ProtectedCustomDictionary<string, int>(new Dictionary<string, int>()
{
["key1"] = 1,
["key2"] = 2,
["key3"] = 2,
});
SerializeAndAssertEquivalent(customDict);
}

private void SerializeAndAssertEquivalent<T>(T expected)
{
Serialize(expected);
Expand All @@ -27,6 +53,24 @@ private void SerializeAndAssertEquivalent<T>(T expected)
AssertMemoryStreamConsumed();
}

class PrivateCustomDictionary<TKey, TValue> : CustomDictionary<TKey, TValue>
{
private PrivateCustomDictionary() : base(new Dictionary<TKey, TValue>())
{ }

public PrivateCustomDictionary(Dictionary<TKey, TValue> dict) : base(new Dictionary<TKey, TValue>())
{ }
}

class ProtectedCustomDictionary<TKey, TValue> : CustomDictionary<TKey, TValue>
{
protected ProtectedCustomDictionary() : base(new Dictionary<TKey, TValue>())
{ }

public ProtectedCustomDictionary(Dictionary<TKey, TValue> dict) : base(new Dictionary<TKey, TValue>())
{ }
}

/// <summary>
/// Just a custom class wrapper for another <see cref="IDictionary{TKey,TValue}"/>
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Hyperion.Tests/Hyperion.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.10.0" />
<PackageReference Include="FluentAssertions" Version="5.10.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="1.7.0" />
<PackageReference Include="xunit" Version="$(XunitVersion)" />
Expand Down
4 changes: 3 additions & 1 deletion src/Hyperion/Hyperion.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

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

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="System.Runtime" Version="4.3.1" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' Or '$(TargetFramework)' == 'netstandard1.6' ">
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,14 @@ public override ValueSerializer BuildSerializer(Serializer serializer, Type type

ObjectReader reader = (stream, session) =>
{
var instance = Activator.CreateInstance(type); // IDictionary<TKey, TValue>
object instance;
try
{
instance = Activator.CreateInstance(type, true); // IDictionary<TKey, TValue>
} catch(Exception) {
instance = Activator.CreateInstance(type); // IDictionary<TKey, TValue>
}

if (preserveObjectReferences)
{
session.TrackDeserializedObject(instance);
Expand Down