Skip to content

Commit f3fc721

Browse files
Added pragma to suppress CS1591 in generated code
1 parent 7f26caa commit f3fc721

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

src/Framework/AspNetCoreAnalyzers/src/SourceGenerators/PublicTopLevelProgramGenerator.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ public class PublicProgramSourceGenerator : IIncrementalGenerator
1212
{
1313
private const string PublicPartialProgramClassSource = """
1414
// <auto-generated />
15+
#pragma warning disable CS1591
1516
public partial class Program { }
17+
#pragma warning restore CS1591
1618
""";
1719

1820
public void Initialize(IncrementalGeneratorInitializationContext context)
@@ -21,16 +23,16 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
2123
// Get the entry point associated with the compilation, this maps to the Main method definition
2224
// Get the containing symbol of the entry point, this maps to the Program class
2325
compilation.GetEntryPoint(cancellationToken)?.ContainingSymbol is INamedTypeSymbol
24-
{
25-
// If the discovered `Program` type is not a class then its not
26-
// generated and has been defined in source, so we can skip it
27-
// If the program class is already public, we don't need to generate anything.
28-
DeclaredAccessibility: not Accessibility.Public,
29-
TypeKind: TypeKind.Class,
30-
// If there are multiple partial declarations, then do nothing since we don't want
31-
// to trample on visibility explicitly set by the user
32-
DeclaringSyntaxReferences: { Length: 1 } declaringSyntaxReferences
33-
} &&
26+
{
27+
// If the discovered `Program` type is not a class then its not
28+
// generated and has been defined in source, so we can skip it
29+
// If the program class is already public, we don't need to generate anything.
30+
DeclaredAccessibility: not Accessibility.Public,
31+
TypeKind: TypeKind.Class,
32+
// If there are multiple partial declarations, then do nothing since we don't want
33+
// to trample on visibility explicitly set by the user
34+
DeclaringSyntaxReferences: { Length: 1 } declaringSyntaxReferences
35+
} &&
3436
// If the `Program` class is already declared in user code, we don't need to generate anything.
3537
declaringSyntaxReferences.Single().GetSyntax(cancellationToken) is not ClassDeclarationSyntax
3638
);

src/Framework/AspNetCoreAnalyzers/test/SourceGenerators/PublicTopLevelProgramGeneratorTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ public async Task GeneratesSource_ProgramWithTopLevelStatements()
2222

2323
var expected = """
2424
// <auto-generated />
25+
#pragma warning disable CS1591
2526
public partial class Program { }
27+
#pragma warning restore CS1591
2628
""";
2729

2830
await VerifyCS.VerifyAsync(source, "PublicTopLevelProgram.Generated.g.cs", expected);

0 commit comments

Comments
 (0)