From ea3a594f103100b13f26c3d620ccefdfc876fdf8 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Wed, 4 Mar 2026 19:24:23 +0000
Subject: [PATCH 1/2] Initial plan
From c8c4fcf56e20f2fd933f580aef94e132688822e0 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Wed, 4 Mar 2026 19:28:24 +0000
Subject: [PATCH 2/2] Mark generated files and suppress warnings
Co-authored-by: dex3r <3155725+dex3r@users.noreply.github.com>
---
.../GeneratesMethodPatternSourceBuilder.cs | 5 ++++
.../BoolSwitchKeyTests.cs | 10 +++++++
.../GeneratedCodeTestHelper.cs | 29 +++++++++++++++++++
3 files changed, 44 insertions(+)
diff --git a/EasySourceGenerators.Generators/GeneratesMethodPatternSourceBuilder.cs b/EasySourceGenerators.Generators/GeneratesMethodPatternSourceBuilder.cs
index 3d40772..5aab0ba 100644
--- a/EasySourceGenerators.Generators/GeneratesMethodPatternSourceBuilder.cs
+++ b/EasySourceGenerators.Generators/GeneratesMethodPatternSourceBuilder.cs
@@ -261,6 +261,11 @@ private static string GenerateSwitchMethodSource(
private static void AppendNamespaceAndTypeHeader(StringBuilder builder, INamedTypeSymbol containingType, IMethodSymbol partialMethod)
{
+ builder.AppendLine("// ");
+ builder.AppendLine($"// Generated by {typeof(GeneratesMethodGenerator).FullName} for method '{partialMethod.Name}'.");
+ builder.AppendLine("#pragma warning disable");
+ builder.AppendLine();
+
string? namespaceName = containingType.ContainingNamespace?.IsGlobalNamespace == false
? containingType.ContainingNamespace.ToDisplayString()
: null;
diff --git a/EasySourceGenerators.Tests/BoolSwitchKeyTests.cs b/EasySourceGenerators.Tests/BoolSwitchKeyTests.cs
index f9b2ab3..70e947b 100644
--- a/EasySourceGenerators.Tests/BoolSwitchKeyTests.cs
+++ b/EasySourceGenerators.Tests/BoolSwitchKeyTests.cs
@@ -37,6 +37,16 @@ public static partial string GetBoolLabel(bool flag)
Assert.That(generatedCode, Is.EqualTo(expectedCode));
}
+
+ [Test]
+ public void BoolSwitchKey_GeneratedCode_HasAutoGeneratedHeaderAndWarningSuppression()
+ {
+ string generatedCode = GeneratedCodeTestHelper.ReadGeneratedCodeRaw("TestBoolSwitchClass_GetBoolLabel.g.cs");
+
+ Assert.That(generatedCode, Does.StartWith("// "));
+ Assert.That(generatedCode, Does.Contain("Generated by EasySourceGenerators.Generators.GeneratesMethodGenerator for method 'GetBoolLabel'"));
+ Assert.That(generatedCode, Does.Contain("#pragma warning disable"));
+ }
}
public static partial class TestBoolSwitchClass
diff --git a/EasySourceGenerators.Tests/GeneratedCodeTestHelper.cs b/EasySourceGenerators.Tests/GeneratedCodeTestHelper.cs
index ba4f5ef..091b472 100644
--- a/EasySourceGenerators.Tests/GeneratedCodeTestHelper.cs
+++ b/EasySourceGenerators.Tests/GeneratedCodeTestHelper.cs
@@ -5,11 +5,40 @@ internal static class GeneratedCodeTestHelper
private const char UnicodeBom = '\uFEFF';
internal static string ReadGeneratedCode(string generatedFileName)
+ {
+ string rawCode = ReadGeneratedCodeRaw(generatedFileName);
+ return StripGeneratedPreamble(rawCode);
+ }
+
+ internal static string ReadGeneratedCodeRaw(string generatedFileName)
{
string generatedCodePath = GetGeneratedCodePath(generatedFileName);
return File.ReadAllText(generatedCodePath).TrimStart(UnicodeBom).ReplaceLineEndings("\n").TrimEnd();
}
+ private static string StripGeneratedPreamble(string generatedCode)
+ {
+ string[] lines = generatedCode.Split('\n');
+ int index = 0;
+
+ while (index < lines.Length)
+ {
+ string currentLine = lines[index];
+ bool isGeneratedPreambleLine = currentLine.StartsWith("//", StringComparison.Ordinal)
+ || currentLine.StartsWith("#pragma warning disable", StringComparison.Ordinal)
+ || string.IsNullOrWhiteSpace(currentLine);
+
+ if (!isGeneratedPreambleLine)
+ {
+ break;
+ }
+
+ index++;
+ }
+
+ return string.Join('\n', lines[index..]).TrimEnd();
+ }
+
private static string GetGeneratedCodePath(string generatedFileName)
{
string projectDirectory = FindProjectDirectory();