From 4eff11c9dfa900d7922e2dacf83bf1ebe0bedcfa Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Tue, 16 Feb 2021 17:00:58 -0700 Subject: [PATCH] Prefer `bool` over `BOOL` in method signatures --- src/Microsoft.Windows.CsWin32/Generator.cs | 1 + .../GeneratorTests.cs | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/Microsoft.Windows.CsWin32/Generator.cs b/src/Microsoft.Windows.CsWin32/Generator.cs index 110d0d87..2b7bdd37 100644 --- a/src/Microsoft.Windows.CsWin32/Generator.cs +++ b/src/Microsoft.Windows.CsWin32/Generator.cs @@ -35,6 +35,7 @@ public class Generator : IDisposable { { nameof(System.Runtime.InteropServices.ComTypes.FILETIME), ParseTypeName("System.Runtime.InteropServices.ComTypes.FILETIME") }, { nameof(Guid), ParseTypeName("System.Guid") }, + { "BOOL", PredefinedType(Token(SyntaxKind.BoolKeyword)) }, { "OLD_LARGE_INTEGER", PredefinedType(Token(SyntaxKind.LongKeyword)) }, { "LARGE_INTEGER", PredefinedType(Token(SyntaxKind.LongKeyword)) }, { "ULARGE_INTEGER", PredefinedType(Token(SyntaxKind.ULongKeyword)) }, diff --git a/test/Microsoft.Windows.CsWin32.Tests/GeneratorTests.cs b/test/Microsoft.Windows.CsWin32.Tests/GeneratorTests.cs index df4bc233..2162242c 100644 --- a/test/Microsoft.Windows.CsWin32.Tests/GeneratorTests.cs +++ b/test/Microsoft.Windows.CsWin32.Tests/GeneratorTests.cs @@ -166,6 +166,18 @@ public void CreateFileUsesSafeHandles() Assert.Equal("SafeHandle", createFileMethod.ParameterList.Parameters.Last().Type?.ToString()); } + [Fact] + public void BOOL_ReturnTypeBecomes_Boolean() + { + this.generator = new Generator(this.metadataStream, compilation: this.compilation, parseOptions: this.parseOptions); + Assert.True(this.generator.TryGenerate("WinUsb_FlushPipe", CancellationToken.None)); + this.CollectGeneratedCode(this.generator); + this.AssertNoDiagnostics(); + MethodDeclarationSyntax? createFileMethod = this.FindGeneratedMethod("WinUsb_FlushPipe"); + Assert.NotNull(createFileMethod); + Assert.Equal(SyntaxKind.BoolKeyword, Assert.IsType(createFileMethod!.ReturnType).Keyword.Kind()); + } + [Fact] public void BSTR_FieldsDoNotBecomeSafeHandles() {