From 5e14c4fb272f3b170e7c0855921bfb9fc63eea1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Boh=C3=A1=C4=8Dek?= Date: Wed, 29 Dec 2021 22:41:09 +0100 Subject: [PATCH] feat: implement adding generated serializers --- .../Extensions/ServiceCollectionExtensions.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Core/NosSmooth.Packets/Extensions/ServiceCollectionExtensions.cs b/Core/NosSmooth.Packets/Extensions/ServiceCollectionExtensions.cs index 41b6007..4e7e6b1 100644 --- a/Core/NosSmooth.Packets/Extensions/ServiceCollectionExtensions.cs +++ b/Core/NosSmooth.Packets/Extensions/ServiceCollectionExtensions.cs @@ -46,7 +46,17 @@ public static class ServiceCollectionExtensions /// The collection. public static IServiceCollection AddGeneratedSerializers(this IServiceCollection serviceCollection, Assembly assembly) { - throw new NotImplementedException(); + var types = assembly.GetExportedTypes() + .Where(x => x.Namespace?.Contains("Generated") ?? false) + .Where(x => x.GetInterfaces().Any( + i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(ITypeConverter<>) + )); + foreach (var type in types) + { + serviceCollection.AddTypeConverter(type); + } + + return serviceCollection; } /// -- 2.49.0