Skip to content

Commit

Permalink
Merge pull request #1229 from AArnott/fix1217
Browse files Browse the repository at this point in the history
Add support for `IReadOnlySet<T>`
  • Loading branch information
AArnott committed May 17, 2021
2 parents 27230c7 + 752022e commit 7af6eea
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 6 deletions.
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "5.0.100",
"version": "5.0.201",
"rollForward": "patch",
"allowPrerelease": false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1271,6 +1271,28 @@ protected override HashSet<T> Create(int count, MessagePackSerializerOptions opt
}
}

#if NET5_0_OR_GREATER

public sealed class InterfaceReadOnlySetFormatter<T> : CollectionFormatterBase<T, HashSet<T>, IReadOnlySet<T>>
{
protected override void Add(HashSet<T> collection, int index, T value, MessagePackSerializerOptions options)
{
collection.Add(value);
}

protected override IReadOnlySet<T> Complete(HashSet<T> intermediateCollection)
{
return intermediateCollection;
}

protected override HashSet<T> Create(int count, MessagePackSerializerOptions options)
{
return new HashSet<T>(options.Security.GetEqualityComparer<T>());
}
}

#endif

public sealed class ConcurrentBagFormatter<T> : CollectionFormatterBase<T, System.Collections.Concurrent.ConcurrentBag<T>>
{
protected override int? GetCount(ConcurrentBag<T> sequence)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ public T Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions
}
}

#if NET5_0
#if NET5_0_OR_GREATER

public sealed class HalfFormatter : IMessagePackFormatter<Half>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ internal static class BuiltinResolverGetFormatterHelper
{ typeof(System.Numerics.Complex), ComplexFormatter.Instance },
{ typeof(System.Numerics.Complex?), new StaticNullableFormatter<System.Numerics.Complex>(ComplexFormatter.Instance) },

#if NET5_0
#if NET5_0_OR_GREATER
{ typeof(System.Half), HalfFormatter.Instance },
#endif
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ internal static class DynamicGenericResolverGetFormatterHelper
{ typeof(IReadOnlyList<>), typeof(InterfaceReadOnlyListFormatter<>) },
{ typeof(IReadOnlyCollection<>), typeof(InterfaceReadOnlyCollectionFormatter<>) },
{ typeof(ISet<>), typeof(InterfaceSetFormatter<>) },
#if NET5_0_OR_GREATER
{ typeof(IReadOnlySet<>), typeof(InterfaceReadOnlySetFormatter<>) },
#endif
{ typeof(System.Collections.Concurrent.ConcurrentBag<>), typeof(ConcurrentBagFormatter<>) },
{ typeof(System.Collections.Concurrent.ConcurrentQueue<>), typeof(ConcurrentQueueFormatter<>) },
{ typeof(System.Collections.Concurrent.ConcurrentStack<>), typeof(ConcurrentStackFormatter<>) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public void UriTest_Relative()
this.Convert(relative).ToString().Is("/me/");
}

#if NET5_0
#if NET5_0_OR_GREATER

[Fact]
public void HalfTest()
Expand Down
2 changes: 2 additions & 0 deletions src/MessagePack/net5.0/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ MessagePack.FormatterNotRegisteredException.FormatterNotRegisteredException(Syst
MessagePack.Formatters.HalfFormatter
MessagePack.Formatters.HalfFormatter.Deserialize(ref MessagePack.MessagePackReader reader, MessagePack.MessagePackSerializerOptions options) -> System.Half
MessagePack.Formatters.HalfFormatter.Serialize(ref MessagePack.MessagePackWriter writer, System.Half value, MessagePack.MessagePackSerializerOptions options) -> void
MessagePack.Formatters.InterfaceReadOnlySetFormatter<T>
MessagePack.Formatters.InterfaceReadOnlySetFormatter<T>.InterfaceReadOnlySetFormatter() -> void
MessagePack.MessagePackReader.MessagePackReader() -> void
MessagePack.MessagePackSerializerOptions.SequencePool.get -> MessagePack.SequencePool
MessagePack.MessagePackSerializerOptions.WithPool(MessagePack.SequencePool pool) -> MessagePack.MessagePackSerializerOptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using Xunit;

#if NET5_0
#if NET5_0_OR_GREATER

namespace MessagePack.Tests
{
Expand Down
2 changes: 1 addition & 1 deletion tests/MessagePack.Tests/IsExternalInit.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) All contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#if !NET5_0
#if !NET5_0_OR_GREATER

#pragma warning disable CA1812

Expand Down

0 comments on commit 7af6eea

Please sign in to comment.