Skip to content

Commit 69ce272

Browse files
authored
Merge pull request #919 from Cysharp/hotfix/UpdateKnownFormatterMapping
Fix missing Formatter mappings
2 parents 53f6d1f + 186f4a5 commit 69ce272

File tree

4 files changed

+157
-55
lines changed

4 files changed

+157
-55
lines changed

src/MagicOnion.Client.SourceGenerator/CodeAnalysis/SerializationFormatterNameMapper.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,30 @@ class MessagePackWellKnownSerializationTypes : IWellKnownSerializationTypes
8383
public IReadOnlyDictionary<string, string> GenericFormattersMap { get; } = new Dictionary<string, string>
8484
{
8585
{"global::System.Nullable<>", "global::MessagePack.Formatters.NullableFormatter" },
86+
// https://github.com/MessagePack-CSharp/MessagePack-CSharp/blob/v3.0.300/src/MessagePack/Resolvers/DynamicGenericResolver.cs#L52
8687
{"global::System.Collections.Generic.List<>", "global::MessagePack.Formatters.ListFormatter" },
88+
{"global::System.Collections.Generic.LinkedList<>", "global::MessagePack.Formatters.LinkedListFormatter" },
89+
{"global::System.Collections.Generic.Queue<>", "global::MessagePack.Formatters.QueueFormatter" },
90+
//{"global::System.Collections.Generic.PriorityQueue<,>", "global::MessagePack.Formatters.PriorityQueueFormatter" },
91+
{"global::System.Collections.Generic.Stack<>", "global::MessagePack.Formatters.StackFormatter" },
92+
{"global::System.Collections.Generic.HashSet<>", "global::MessagePack.Formatters.HashSetFormatter" },
93+
{"global::System.Collections.ObjectModel.ReadOnlyCollection<>", "global::MessagePack.Formatters.ReadOnlyCollectionFormatter" },
8794
{"global::System.Collections.Generic.IList<>", "global::MessagePack.Formatters.InterfaceListFormatter2" },
88-
{"global::System.Collections.Generic.IReadOnlyList<>", "global::MessagePack.Formatters.InterfaceReadOnlyListFormatter" },
89-
{"global::System.Collections.Generic.Dictionary<,>", "global::MessagePack.Formatters.DictionaryFormatter"},
90-
{"global::System.Collections.Generic.IDictionary<,>", "global::MessagePack.Formatters.InterfaceDictionaryFormatter"},
91-
{"global::System.Collections.Generic.IReadOnlyDictionary<,>", "global::MessagePack.Formatters.InterfaceReadOnlyDictionaryFormatter"},
9295
{"global::System.Collections.Generic.ICollection<>", "global::MessagePack.Formatters.InterfaceCollectionFormatter2" },
93-
{"global::System.Collections.Generic.IReadOnlyCollection<>", "global::MessagePack.Formatters.InterfaceReadOnlyCollectionFormatter" },
9496
{"global::System.Collections.Generic.IEnumerable<>", "global::MessagePack.Formatters.InterfaceEnumerableFormatter" },
95-
{"global::System.Collections.Generic.KeyValuePair<,>", "global::MessagePack.Formatters.KeyValuePairFormatter" },
97+
{"global::System.Collections.Generic.Dictionary<,>", "global::MessagePack.Formatters.DictionaryFormatter"},
98+
{"global::System.Collections.Generic.IDictionary<,>", "global::MessagePack.Formatters.InterfaceDictionaryFormatter"},
99+
{"global::System.Collections.Generic.SortedDictionary<,>", "global::MessagePack.Formatters.SortedDictionaryFormatter"},
100+
{"global::System.Collections.Generic.SortedList<,>", "global::MessagePack.Formatters.SortedListFormatter"},
96101
{"global::System.Linq.ILookup<,>", "global::MessagePack.Formatters.InterfaceLookupFormatter" },
97102
{"global::System.Linq.IGrouping<,>", "global::MessagePack.Formatters.InterfaceGroupingFormatter" },
103+
{"global::System.Collections.Generic.IReadOnlyList<>", "global::MessagePack.Formatters.InterfaceReadOnlyListFormatter" },
104+
{"global::System.Collections.Generic.IReadOnlyCollection<>", "global::MessagePack.Formatters.InterfaceReadOnlyCollectionFormatter" },
105+
{"global::System.Collections.Generic.ISet<>", "global::MessagePack.Formatters.InterfaceSetFormatter" },
106+
{"global::System.Collections.Generic.IReadOnlySet<>", "global::MessagePack.Formatters.InterfaceReadOnlySetFormatter" },
107+
{"global::System.Collections.ObjectModel.ReadOnlyDictionary<,>", "global::MessagePack.Formatters.ReadOnlyDictionaryFormatter"},
108+
{"global::System.Collections.Generic.IReadOnlyDictionary<,>", "global::MessagePack.Formatters.InterfaceReadOnlyDictionaryFormatter"},
109+
{"global::System.Collections.Generic.KeyValuePair<,>", "global::MessagePack.Formatters.KeyValuePairFormatter" },
98110
{"global::System.Tuple<>", "global::MessagePack.Formatters.TupleFormatter" },
99111
{"global::System.Tuple<,>", "global::MessagePack.Formatters.TupleFormatter" },
100112
{"global::System.Tuple<,,>", "global::MessagePack.Formatters.TupleFormatter" },

tests/MagicOnion.Client.SourceGenerator.Tests/GenerateGenericsTest.cs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,9 @@ public async Task KnownFormatters()
684684
{
685685
var source = """
686686
using System;
687+
using System.Collections;
687688
using System.Collections.Generic;
689+
using System.Collections.ObjectModel;
688690
using System.Linq;
689691
using System.Threading.Tasks;
690692
using MessagePack;
@@ -695,20 +697,35 @@ namespace TempProject
695697
{
696698
public interface IMyService : IService<IMyService>
697699
{
700+
// https://github.com/MessagePack-CSharp/MessagePack-CSharp/blob/v3.0.300/src/MessagePack/Resolvers/DynamicGenericResolver.cs#L52
698701
UnaryResult<List<MyResponse>> MethodList(List<int> args);
702+
UnaryResult<LinkedList<MyResponse>> MethodLinkedList(LinkedList<int> args);
703+
UnaryResult<Queue<MyResponse>> MethodQueue();
704+
//UnaryResult<PriorityQueue<int,MyResponse>> MethodPriorityQueue();
705+
UnaryResult<Stack<MyResponse>> MethodStack();
706+
UnaryResult<HashSet<MyResponse>> MethodHashSet();
707+
UnaryResult<ReadOnlyCollection<MyResponse>> MethodROCollection();
708+
699709
UnaryResult<IList<MyResponse>> MethodIList();
700-
UnaryResult<IReadOnlyList<MyResponse>> MethodIROList();
710+
UnaryResult<ICollection<MyResponse>> MethodICollection();
711+
UnaryResult<IEnumerable<MyResponse>> MethodIEnumerable();
701712
702713
UnaryResult<Dictionary<string, MyResponse>> MethodDictionary();
703714
UnaryResult<IDictionary<string, MyResponse>> MethodIDictionary();
704-
UnaryResult<IReadOnlyDictionary<string, MyResponse>> MethodIRODictionary();
705-
706-
UnaryResult<IEnumerable<MyResponse>> MethodIEnumerable();
707-
UnaryResult<ICollection<MyResponse>> MethodICollection();
708-
UnaryResult<IReadOnlyCollection<MyResponse>> MethodIROCollection();
715+
UnaryResult<SortedDictionary<string, MyResponse>> MethodSortedDictionary();
716+
UnaryResult<SortedList<int, MyResponse>> MethodSortedList();
709717
710718
UnaryResult<ILookup<int, MyResponse>> MethodILookup();
711719
UnaryResult<IGrouping<int, MyResponse>> MethodIGrouping();
720+
721+
UnaryResult<ISet<MyResponse>> MethodISet();
722+
UnaryResult<IReadOnlySet<MyResponse>> MethodIROSet();
723+
724+
UnaryResult<IReadOnlyCollection<MyResponse>> MethodIROCollection();
725+
UnaryResult<IReadOnlyList<MyResponse>> MethodIROList();
726+
UnaryResult<IReadOnlyDictionary<string, MyResponse>> MethodIRODictionary();
727+
UnaryResult<ReadOnlyDictionary<string, MyResponse>> MethodRODictionary();
728+
712729
}
713730
public class MyResponse
714731
{

0 commit comments

Comments
 (0)