From 3a4b8d1a5eeb1dc4a7138900baddd75f2531270a Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Fri, 19 Jan 2024 15:06:26 +0000 Subject: [PATCH] feat: Generate calls to GetEffectiveSettings in the client builder This will allow API key support to be introduced through partial classes. Requires https://github.com/googleapis/gax-dotnet/pull/732 to be merged and released. --- .../Generation/ServiceBuilderCodeGenerator.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Google.Api.Generator/Generation/ServiceBuilderCodeGenerator.cs b/Google.Api.Generator/Generation/ServiceBuilderCodeGenerator.cs index 388cfeac..0d76b360 100644 --- a/Google.Api.Generator/Generation/ServiceBuilderCodeGenerator.cs +++ b/Google.Api.Generator/Generation/ServiceBuilderCodeGenerator.cs @@ -103,11 +103,13 @@ private MethodDeclarationSyntax BuildImpl() { var callInvoker = Local(_ctx.Type(), "callInvoker"); var logger = Property(Public, _ctx.Type(), nameof(ClientBuilderBase.Logger)); + var settingsClone = IdentifierName("Settings").Call("Clone", conditional: true)(); + var effectiveSettings = This.Call("GetEffectiveSettings")(settingsClone); return Method(Private, _ctx.Type(_svc.ClientAbstractTyp), "BuildImpl")() .WithBody( This.Call("Validate")(), callInvoker.WithInitializer(This.Call("CreateCallInvoker")()), - Return(_ctx.Type(_svc.ClientAbstractTyp).Call("Create")(callInvoker, Settings(), logger))); + Return(_ctx.Type(_svc.ClientAbstractTyp).Call("Create")(callInvoker, effectiveSettings, logger))); } private MethodDeclarationSyntax BuildAsyncImpl() @@ -115,11 +117,13 @@ private MethodDeclarationSyntax BuildAsyncImpl() var cancellationToken = Parameter(_ctx.Type(), "cancellationToken"); var callInvoker = Local(_ctx.Type(), "callInvoker"); var logger = Property(Public, _ctx.Type(), nameof(ClientBuilderBase.Logger)); + var settingsClone = IdentifierName("Settings").Call("Clone", conditional: true)(); + var effectiveSettings = This.Call("GetEffectiveSettings")(settingsClone); return Method(Private | Async, _ctx.Type(Typ.Generic(typeof(Task<>), _svc.ClientAbstractTyp)), "BuildAsyncImpl")(cancellationToken) .WithBody( This.Call("Validate")(), callInvoker.WithInitializer(Await(This.Call("CreateCallInvokerAsync")(cancellationToken).ConfigureAwait())), - Return(_ctx.Type(_svc.ClientAbstractTyp).Call("Create")(callInvoker, Settings(), logger))); + Return(_ctx.Type(_svc.ClientAbstractTyp).Call("Create")(callInvoker, effectiveSettings, logger))); } private MethodDeclarationSyntax GetChannelPool() =>