Skip to content

Commit 53e2b85

Browse files
committed
Fix visibility of macros
1 parent 18aed91 commit 53e2b85

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/Microsoft.Windows.CsWin32/Generator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1605,7 +1605,7 @@ internal void RequestMacro(MethodDeclarationSyntax macro)
16051605
{
16061606
this.volatileCode.GenerateMacro(macro.Identifier.ValueText, delegate
16071607
{
1608-
this.volatileCode.AddMacro(macro.Identifier.ValueText, macro);
1608+
this.volatileCode.AddMacro(macro.Identifier.ValueText, (MethodDeclarationSyntax)ElevateVisibility(macro));
16091609

16101610
// Generate any additional types that this macro relies on.
16111611
foreach (QualifiedNameSyntax identifier in macro.DescendantNodes().OfType<QualifiedNameSyntax>())

test/Microsoft.Windows.CsWin32.Tests/GeneratorTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,18 @@ public void HandleStructsHaveStaticNullMember(string handleName)
607607
this.AssertGeneratedMember(handleName, "Null", $"internal static {handleName} Null => default;");
608608
}
609609

610+
[Theory, PairwiseData]
611+
public void MacroAPIsGenerateWithAppropriateVisibility(bool publicVisibility)
612+
{
613+
this.generator = this.CreateGenerator(DefaultTestGeneratorOptions with { Public = publicVisibility });
614+
Assert.True(this.generator.TryGenerate("HRESULT_FROM_WIN32", CancellationToken.None));
615+
this.CollectGeneratedCode(this.generator);
616+
this.AssertNoDiagnostics();
617+
var method = Assert.Single(this.FindGeneratedMethod("HRESULT_FROM_WIN32"));
618+
619+
Assert.True(method.Modifiers.Any(publicVisibility ? SyntaxKind.PublicKeyword : SyntaxKind.InternalKeyword));
620+
}
621+
610622
[Theory]
611623
[InlineData("HRESULT_FROM_WIN32")]
612624
public void MacroAPIsGenerate(string macro)

0 commit comments

Comments
 (0)