Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate more friendly overloads on net35 #892

Merged
merged 1 commit into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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