~ruther/NosSmooth

e919f25435644fe473305b372cde3a0de9e02350 — František Boháček 2 years ago 8ab46d3
fix(packets): try to find specific serializer before building one using a generator
1 files changed, 9 insertions(+), 3 deletions(-)

M Packets/NosSmooth.PacketSerializer/Converters/StringConverterRepository.cs
M Packets/NosSmooth.PacketSerializer/Converters/StringConverterRepository.cs => Packets/NosSmooth.PacketSerializer/Converters/StringConverterRepository.cs +9 -3
@@ 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<IStringConverter?>.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<IStringConverter?>.FromSuccess
                    ((IStringConverter?)_serviceProvider.GetService(converterType));
                return Result<IStringConverter?>.FromSuccess(null);
            }
        );


Do not follow this link