From dfe0b5713c2821a31b7b1245fbd1d4247a44ae29 Mon Sep 17 00:00:00 2001 From: "Simon G." Date: Wed, 3 Dec 2025 11:02:24 +0100 Subject: [PATCH] - implement clear multiton instance method --- .../FactoryGenerator.cs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/LightweightIocContainer.FactoryGenerator/FactoryGenerator.cs b/LightweightIocContainer.FactoryGenerator/FactoryGenerator.cs index 8731cdf..4bbab00 100644 --- a/LightweightIocContainer.FactoryGenerator/FactoryGenerator.cs +++ b/LightweightIocContainer.FactoryGenerator/FactoryGenerator.cs @@ -241,9 +241,20 @@ public class FactoryGenerator : IIncrementalGenerator stringBuilder.AppendLine($"{INDENT}}}"); } - else if (method.Name == CLEAR_MULTITON_INSTANCE_METHOD_NAME) + else if (method is { Name: CLEAR_MULTITON_INSTANCE_METHOD_NAME, IsGenericMethod: true }) { - //TODO + stringBuilder.Append($"{INDENT}public void {method.Name}<{string.Join(", ", method.TypeParameters.Select(p => p.Name))}>()"); + + foreach (ITypeParameterSymbol typeParameter in method.TypeParameters) + { + List parameterConstraints = GetParameterConstraints(typeParameter); + if (parameterConstraints.Count == 0) + continue; + + stringBuilder.Append($" where {typeParameter.Name} : {string.Join(", ", parameterConstraints)}"); + } + + stringBuilder.AppendLine($" => container.ClearMultitonInstances<{string.Join(", ", method.TypeArguments.Select(a => a.Name))}>();"); } }