From 2eb521d783234892be6b8f1c61bd4ac2d03218ef Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Sun, 13 Sep 2026 12:43:14 +0000
Subject: [PATCH 1/2] Initial plan
From feb76d159d5872ebde8c00a41838c120847c1b5c Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Sun, 13 Sep 2026 12:46:47 +0000
Subject: [PATCH 2/2] Handle empty PragmaScope warning lists as no-op
Co-authored-by: matt-edmondson <19528727+matt-edmondson@users.noreply.github.com>
---
CodeBlocker.Test/ScopesTests.cs | 33 +++++++++++++++++++++++++++++++++
CodeBlocker/Scopes.cs | 13 ++++++++++++-
2 files changed, 45 insertions(+), 1 deletion(-)
diff --git a/CodeBlocker.Test/ScopesTests.cs b/CodeBlocker.Test/ScopesTests.cs
index 51e9788..86716eb 100644
--- a/CodeBlocker.Test/ScopesTests.cs
+++ b/CodeBlocker.Test/ScopesTests.cs
@@ -135,6 +135,39 @@ public void PragmaScopeJoinsSeveralWarnings()
codeBlocker.ToString());
}
+ [TestMethod]
+ public void PragmaScopeWithAnEmptyStringIsANoOp()
+ {
+ using CodeBlocker codeBlocker = Create();
+
+ using (new PragmaScope(codeBlocker, ""))
+ {
+ codeBlocker.WriteLine("public int Value;");
+ }
+
+ Assert.AreEqual("public int Value;\n", codeBlocker.ToString());
+ }
+
+ [TestMethod]
+ public void PragmaScopeWithAnEmptyWarningSequenceDoesNotAffectAnOuterScope()
+ {
+ using CodeBlocker codeBlocker = Create();
+
+ using (new PragmaScope(codeBlocker, "CS1591"))
+ {
+ using (new PragmaScope(codeBlocker, []))
+ {
+ codeBlocker.WriteLine("public int X;");
+ }
+
+ codeBlocker.WriteLine("public int Y;");
+ }
+
+ Assert.AreEqual(
+ "#pragma warning disable CS1591\npublic int X;\npublic int Y;\n#pragma warning restore CS1591\n",
+ codeBlocker.ToString());
+ }
+
[TestMethod]
public void ScopesOfMixedKindsNestCorrectly()
{
diff --git a/CodeBlocker/Scopes.cs b/CodeBlocker/Scopes.cs
index 170af82..e293b07 100644
--- a/CodeBlocker/Scopes.cs
+++ b/CodeBlocker/Scopes.cs
@@ -159,7 +159,8 @@ private static void End(CodeBlocker codeBlocker)
/// The parent .
///
/// The warning identifiers to suppress, written verbatim after the directive — either a single
-/// identifier such as CS1591 or a comma-separated list.
+/// identifier such as CS1591 or a comma-separated list. Empty or whitespace warnings are a
+/// no-op and emit no directives.
///
public class PragmaScope(CodeBlocker codeBlocker, string warnings)
: ScopedAction(onOpen: () => Begin(codeBlocker, warnings), onClose: () => End(codeBlocker, warnings))
@@ -177,12 +178,22 @@ public PragmaScope(CodeBlocker codeBlocker, IEnumerable warnings)
private static void Begin(CodeBlocker codeBlocker, string warnings)
{
Ensure.NotNull(codeBlocker);
+ if (string.IsNullOrWhiteSpace(warnings))
+ {
+ return;
+ }
+
codeBlocker.WriteLine($"#pragma warning disable {warnings}");
}
private static void End(CodeBlocker codeBlocker, string warnings)
{
Ensure.NotNull(codeBlocker);
+ if (string.IsNullOrWhiteSpace(warnings))
+ {
+ return;
+ }
+
codeBlocker.WriteLine($"#pragma warning restore {warnings}");
}
}