Skip to content

Commit

Permalink
Add support for IReadOnlySet<T>
Browse files Browse the repository at this point in the history
  • Loading branch information
AArnott committed Apr 17, 2021
1 parent 827abd9 commit 752022e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
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
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
2 changes: 2 additions & 0 deletions src/MessagePack/net5.0/PublicAPI.Unshipped.txt
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

0 comments on commit 752022e

Please sign in to comment.