Skip to content

Commit

Permalink
feat: Refactor ClientHelper initialization to use ClientHelper.Options
Browse files Browse the repository at this point in the history
(Test changes in next commit.)
  • Loading branch information
jskeet committed Mar 14, 2024
1 parent f689ab2 commit 4ba6069
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private MemberDeclarationSyntax CtorGrpcClient(PropertyDeclarationSyntax grpcCli
.WithBody(
grpcClientProperty.Assign(grpcClient),
effectiveSettings.WithInitializer(settings.NullCoalesce(_ctx.Type(_svc.SettingsTyp).Call("GetDefault")())),
clientHelper.WithInitializer(New(_ctx.Type<ClientHelper>())(effectiveSettings, logger)),
clientHelper.WithInitializer(ClientHelperInitializer()),
_svc.Methods.OfType<MethodDetails.StandardLro>().Select(m => StandardLroClient(m, logger)),
_svc.Methods.OfType<MethodDetails.NonStandardLro>().Select(m => NonStandardLroClient(m, logger)),
_svc.Mixins.Select(m => MixinClient(m, logger)),
Expand All @@ -124,6 +124,16 @@ private MemberDeclarationSyntax CtorGrpcClient(PropertyDeclarationSyntax grpcCli
XmlDoc.Param(logger, "Optional ", logger.Type, " to use within this client.")
);

object ClientHelperInitializer()
{
var assignments = new List<ObjectInitExpr>
{
new(nameof(ClientHelper.Options.Settings), effectiveSettings),
new(nameof(ClientHelper.Options.Logger), logger)
};
return New(_ctx.Type<ClientHelper>())(New(_ctx.Type<ClientHelper.Options>())().WithInitializer(assignments.ToArray()));
}

SyntaxNode StandardLroClient(MethodDetails.StandardLro lro, ParameterSyntax logger)
{
var lroOperationsClientProperty = Property(Public, _ctx.Type<OperationsClient>(), lro.LroClientName);
Expand Down

0 comments on commit 4ba6069

Please sign in to comment.