Skip to content

Commit

Permalink
Merge pull request #892 from microsoft/fix888
Browse files Browse the repository at this point in the history
Generate more friendly overloads on net35
  • Loading branch information
AArnott committed Mar 20, 2023
2 parents 27f494b + 62df282 commit d3c7f4c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Microsoft.Windows.CsWin32/Generator.FriendlyOverloads.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@ private IEnumerable<MethodDeclarationSyntax> DeclareFriendlyOverloads(MethodDefi
}
else if ((externParam.Type is PointerTypeSyntax { ElementType: TypeSyntax ptrElementType }
&& !IsVoid(ptrElementType)
&& !this.IsInterface(parameterTypeInfo)
&& this.canUseSpan) ||
&& !this.IsInterface(parameterTypeInfo)) ||
externParam.Type is ArrayTypeSyntax)
{
TypeSyntax elementType = externParam.Type is PointerTypeSyntax ptr ? ptr.ElementType
Expand Down Expand Up @@ -249,6 +248,7 @@ private IEnumerable<MethodDeclarationSyntax> DeclareFriendlyOverloads(MethodDefi
// It is possible that sizeParamIndex points to a parameter that is not on the extern method
// when the parameter is the last one and was moved to a return value.
if (sizeParamIndex.HasValue
&& this.canUseSpan
&& externMethodDeclaration.ParameterList.Parameters.Count > sizeParamIndex.Value
&& !(externMethodDeclaration.ParameterList.Parameters[sizeParamIndex.Value].Type is PointerTypeSyntax)
&& !(externMethodDeclaration.ParameterList.Parameters[sizeParamIndex.Value].Modifiers.Any(SyntaxKind.OutKeyword) || externMethodDeclaration.ParameterList.Parameters[sizeParamIndex.Value].Modifiers.Any(SyntaxKind.RefKeyword))
Expand Down
11 changes: 11 additions & 0 deletions test/Microsoft.Windows.CsWin32.Tests/GeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ public void TryGetEnumName(string candidate, string? declaringEnum)
Assert.Equal(declaringEnum, actualDeclaringEnum);
}

[Theory]
[MemberData(nameof(TFMData))]
public void CoCreateInstance(string tfm)
{
this.compilation = this.starterCompilations[tfm];
this.generator = this.CreateGenerator(includeDocs: true);
Assert.True(this.generator.TryGenerateExternMethod("CoCreateInstance", out _));
this.CollectGeneratedCode(this.generator);
this.AssertNoDiagnostics();
}

[Theory]
[MemberData(nameof(TFMData))]
public void SimplestMethod(string tfm)
Expand Down

0 comments on commit d3c7f4c

Please sign in to comment.