From 5c7cd6fb1a3c3173f354f8c2f64eb828b97b3565 Mon Sep 17 00:00:00 2001 From: tg-msft Date: Mon, 21 Oct 2024 16:51:47 -0700 Subject: [PATCH] Azure.Provisioning: Avoid excess `null`s in BicepStringBuilder --- .../tests/BasicStorageTests.cs | 3 ++- .../src/Expressions/BicepStringBuilder.cs | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/sdk/provisioning/Azure.Provisioning.Storage/tests/BasicStorageTests.cs b/sdk/provisioning/Azure.Provisioning.Storage/tests/BasicStorageTests.cs index 2f076916fbf44..85272cbda4251 100644 --- a/sdk/provisioning/Azure.Provisioning.Storage/tests/BasicStorageTests.cs +++ b/sdk/provisioning/Azure.Provisioning.Storage/tests/BasicStorageTests.cs @@ -270,11 +270,12 @@ await test.Define( infra.Add(new ProvisioningOutput("blobs_endpoint", typeof(string)) { Value = storage.PrimaryEndpoints.Value!.BlobUri }); // Manually compute the public Azure endpoint + string? nothing = null; BicepValue computed = new BicepStringBuilder() .Append("https://") .Append($"{storage.Name}") - .Append(".blob.core.windows.net"); + .Append($".blob.core.windows.net{nothing}"); infra.Add(new ProvisioningOutput("computed_endpoint", typeof(string)) { Value = computed }); return infra; diff --git a/sdk/provisioning/Azure.Provisioning/src/Expressions/BicepStringBuilder.cs b/sdk/provisioning/Azure.Provisioning/src/Expressions/BicepStringBuilder.cs index 575bf7f6803f4..6e0f194ae6fe8 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Expressions/BicepStringBuilder.cs +++ b/sdk/provisioning/Azure.Provisioning/src/Expressions/BicepStringBuilder.cs @@ -102,10 +102,11 @@ public void AppendFormatted(T t) } else { - _expressions.Add( - t is null ? - BicepSyntax.Null() : - BicepSyntax.Value(t.ToString() ?? "")); + string? s = t?.ToString(); + if (s is not null) + { + _expressions.Add(BicepSyntax.Value(s)); + } } }