diff --git a/src/Microsoft.Windows.CsWin32/PointerTypeHandleInfo.cs b/src/Microsoft.Windows.CsWin32/PointerTypeHandleInfo.cs index 86ec04e8..f84ed74c 100644 --- a/src/Microsoft.Windows.CsWin32/PointerTypeHandleInfo.cs +++ b/src/Microsoft.Windows.CsWin32/PointerTypeHandleInfo.cs @@ -29,7 +29,7 @@ internal override TypeSyntaxAndMarshaling ToTypeSyntax(TypeSyntaxSettings inputs // But this pointer represents an array, so type as an array. return new TypeSyntaxAndMarshaling( ArrayType(elementSyntax).AddRankSpecifiers(ArrayRankSpecifier()), - marshalAs is object ? new MarshalAsAttribute(UnmanagedType.LPArray) { ArraySubType = marshalAs.Value } : null); + marshalAs is object ? new MarshalAsAttribute(UnmanagedType.LPArray) { ArraySubType = marshalAs.Value } : new MarshalAsAttribute(UnmanagedType.LPArray)); } else if (xIn || xOut) { diff --git a/test/Microsoft.Windows.CsWin32.Tests/GeneratorTests.cs b/test/Microsoft.Windows.CsWin32.Tests/GeneratorTests.cs index 1fdd897b..bcda75f1 100644 --- a/test/Microsoft.Windows.CsWin32.Tests/GeneratorTests.cs +++ b/test/Microsoft.Windows.CsWin32.Tests/GeneratorTests.cs @@ -341,6 +341,28 @@ public void BOOL_ReturnTypeBecomes_Boolean() Assert.Equal(SyntaxKind.BoolKeyword, Assert.IsType(createFileMethod!.ReturnType).Keyword.Kind()); } + [Theory, PairwiseData] + public void NativeArray_OfManagedTypes_MarshaledAsLPArray(bool allowMarshaling) + { + const string ifaceName = "ID3D11DeviceContext"; + this.generator = this.CreateGenerator(DefaultTestGeneratorOptions with { AllowMarshaling = allowMarshaling }); + Assert.True(this.generator.TryGenerate(ifaceName, CancellationToken.None)); + this.CollectGeneratedCode(this.generator); + this.AssertNoDiagnostics(); + + var generatedMethod = this.FindGeneratedMethod("OMSetRenderTargets").Where(m => m.ParameterList.Parameters.Count == 3 && m.ParameterList.Parameters[0].Identifier.ValueText == "NumViews").FirstOrDefault(); + Assert.NotNull(generatedMethod); + + if (allowMarshaling) + { + Assert.Contains(generatedMethod!.ParameterList.Parameters[1].AttributeLists, al => IsAttributePresent(al, "MarshalAs")); + } + else + { + Assert.DoesNotContain(generatedMethod!.ParameterList.Parameters[1].AttributeLists, al => IsAttributePresent(al, "MarshalAs")); + } + } + [Theory, PairwiseData] public void NativeArray_SizeParamIndex_ProducesSimplerFriendlyOverload(bool allowMarshaling) {