Repository: Azure/azure-sdk-for-net
File: eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/ClientBuilderExtensionsDefinition.cs (C#)

Code before:
            foreach (var client in _publicClients)
            {
                if (client.ClientOptionsParameter == null)
                {
                    continue;
                }

                var tBuilder = typeof(BuilderType<,>).GetGenericArguments()[0];
                var tConfiguration = typeof(BuilderType<,>).GetGenericArguments()[1];
                var builderParameter = new ParameterProvider("builder", $"The builder to register with.", tBuilder);
                var configurationParameter = new ParameterProvider(
                    "configuration",
                    $"The configuration to use for the client.",
                    tConfiguration);
                var methodName = $"Add{client.Name}";
                FormattableString methodDescription =
                    $"Registers a <see cref=\"{client.Name}\"/> client with the specified <see cref=\"{typeof(IAzureClientBuilder<,>)}\"/>.";
                var methodModifiers = MethodSignatureModifiers.Public | MethodSignatureModifiers.Static |
                                      MethodSignatureModifiers.Extension;
                var methodReturnType = new CSharpType(typeof(IAzureClientBuilder<,>), client.Type,
                    client.ClientOptionsParameter.Type);

                // Pre-collect the effective (non-credential, non-options) parameter types for credential constructors
                // to avoid generating duplicate extension methods that favor non-credential versions.
                var comparer = new CSharpType.CSharpTypeIgnoreNullableComparer();
                var credentialParamSets = new List<CSharpType[]>();
                foreach (var ctor in client.CanonicalView.Constructors)
                {
                    if (!ctor.Signature.Modifiers.HasFlag(MethodSignatureModifiers.Public))
                        continue;
                    if (ctor.Signature.Parameters.LastOrDefault()?.Type.Name.Equals(client.ClientOptionsParameter.Type.Name) != true)
                        continue;
                    if (ctor.Signature.Parameters.Count >= 2)
                    {
                        var credType = ctor.Signature.Parameters[^2].Type;
                        if (comparer.Equals(credType, typeof(TokenCredential)) || comparer.Equals(credType, typeof(AzureKeyCredential)))
                        {
                            credentialParamSets.Add(ctor.Signature.Parameters.SkipLast(2).Select(p => p.Type).ToArray());
                        }
                    }
                }

                foreach (var constructor in client.CanonicalView.Constructors)
                {
                    if (!constructor.Signature.Modifiers.HasFlag(MethodSignatureModifiers.Public))
                    {
                        continue;
                    }

                    // Only add overloads for the full constructors that include the client options parameter
                    // Check that the name of the last parameter matches the client options parameter as the namespace will not be resolved for

Review comment (refactor):
@copilot this was a set of string before. Now we are using a list. We can simplify this to be `HashSet<CSharpType>(new CSharpType.CSharpTypeIgnoreNullableComparer());`

Code after:
            foreach (var client in _publicClients)
            {
                if (client.ClientOptionsParameter == null)
                {
                    continue;
                }

                var tBuilder = typeof(BuilderType<,>).GetGenericArguments()[0];
                var tConfiguration = typeof(BuilderType<,>).GetGenericArguments()[1];
                var builderParameter = new ParameterProvider("builder", $"The builder to register with.", tBuilder);
                var configurationParameter = new ParameterProvider(
                    "configuration",
                    $"The configuration to use for the client.",
                    tConfiguration);
                var methodName = $"Add{client.Name}";
                FormattableString methodDescription =
                    $"Registers a <see cref=\"{client.Name}\"/> client with the specified <see cref=\"{typeof(IAzureClientBuilder<,>)}\"/>.";
                var methodModifiers = MethodSignatureModifiers.Public | MethodSignatureModifiers.Static |
                                      MethodSignatureModifiers.Extension;
                var methodReturnType = new CSharpType(typeof(IAzureClientBuilder<,>), client.Type,
                    client.ClientOptionsParameter.Type);

                // Pre-collect the effective (non-credential, non-options) parameter types for credential constructors
                // to avoid generating duplicate extension methods that favor non-credential versions.
                var comparer = new CSharpType.CSharpTypeIgnoreNullableComparer();
                var credentialParamSets = new HashSet<CSharpType>(comparer);
                foreach (var ctor in client.CanonicalView.Constructors)
                {
                    if (!ctor.Signature.Modifiers.HasFlag(MethodSignatureModifiers.Public))
                    {
                        continue;
                    }
                    if (ctor.Signature.Parameters.LastOrDefault()?.Type.Name.Equals(client.ClientOptionsParameter.Type.Name) != true)
                    {
                        continue;
                    }
                    if (ctor.Signature.Parameters.Count >= 2)
                    {
                        var credType = ctor.Signature.Parameters[^2].Type;
                        if (comparer.Equals(credType, typeof(TokenCredential)) || comparer.Equals(credType, typeof(AzureKeyCredential)))
                        {
                            foreach (var param in ctor.Signature.Parameters.SkipLast(2))
                            {
                                credentialParamSets.Add(param.Type);
                            }
                        }
                    }
                }

                foreach (var constructor in client.CanonicalView.Constructors)
                {