From e919f25435644fe473305b372cde3a0de9e02350 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Boh=C3=A1=C4=8Dek?= Date: Thu, 5 Jan 2023 21:31:41 +0100 Subject: [PATCH] fix(packets): try to find specific serializer before building one using a generator --- .../Converters/StringConverterRepository.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Packets/NosSmooth.PacketSerializer/Converters/StringConverterRepository.cs b/Packets/NosSmooth.PacketSerializer/Converters/StringConverterRepository.cs index 0c46c00..27640b2 100644 --- a/Packets/NosSmooth.PacketSerializer/Converters/StringConverterRepository.cs +++ b/Packets/NosSmooth.PacketSerializer/Converters/StringConverterRepository.cs @@ -64,6 +64,14 @@ public class StringConverterRepository : IStringConverterRepository type, (getType) => { + var converterType = typeof(IStringConverter<>).MakeGenericType(type); + var serviceConverter = (IStringConverter?)_serviceProvider.GetService(converterType); + + if (serviceConverter is not null) + { // prefer specific converter to generated one. + return Result.FromSuccess(serviceConverter); + } + foreach (var converterFactory in ConverterFactories) { if (converterFactory.ShouldHandle(getType)) @@ -78,9 +86,7 @@ public class StringConverterRepository : IStringConverterRepository } } - var converterType = typeof(IStringConverter<>).MakeGenericType(type); - return Result.FromSuccess - ((IStringConverter?)_serviceProvider.GetService(converterType)); + return Result.FromSuccess(null); } ); -- 2.49.0