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

Use C# 13 overload resolution attribute to improve friendly overloads #1336

Merged
merged 1 commit into from
Jan 22, 2025

Conversation

AArnott
Copy link
Member

@AArnott AArnott commented Jan 22, 2025

As brought up in #1049 (comment)

C# supports using a polyfill attribute, so this works on any target framework. But it does require C# 13 to reference the attribute on an API or an error results, so CsWin32 only emits or uses the attribute when C# 13 is in operation.

@AArnott AArnott requested a review from Copilot January 22, 2025 20:21
@AArnott AArnott added the enhancement New feature or request label Jan 22, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 5 out of 8 changed files in this pull request and generated 1 comment.

Files not reviewed (3)
  • src/Microsoft.Windows.CsWin32/SimpleSyntaxFactory.cs: Evaluated as low risk
  • src/Microsoft.Windows.CsWin32/Generator.cs: Evaluated as low risk
  • src/Microsoft.Windows.CsWin32/Generator.FriendlyOverloads.cs: Evaluated as low risk
Comments suppressed due to low confidence (4)

src/Microsoft.Windows.CsWin32/Generator.Templates.cs:42

  • [nitpick] The method name TryFetchTemplate is ambiguous as there is already a method with the same name but different parameters. Consider renaming it to TryFetchTemplateCompilationUnit for clarity.
private static bool TryFetchTemplate(string name, Generator? generator, [NotNullWhen(true)] out CompilationUnitSyntax? compilationUnit)

src/Microsoft.Windows.CsWin32/Generator.Templates.cs:44

  • The FetchTemplateText method should handle null values correctly. Ensure that null values are appropriately managed to avoid potential null reference exceptions.
string? template = FetchTemplateText(name);

src/Microsoft.Windows.CsWin32/Generator.Templates.cs:51

  • The new method TryFetchTemplate should be covered by tests to ensure it works as expected. Add test cases to verify its functionality.
compilationUnit = SyntaxFactory.ParseCompilationUnit(template, options: generator?.parseOptions) ?? throw new GenerationFailedException($"Unable to parse compilation unit from a template: {name}");

test/Microsoft.Windows.CsWin32.Tests/GeneratorTestBase.cs:227

  • Verify that the StringSyntax attribute is correctly supported and used in the context of the project.
protected CSharpCompilation AddCode([StringSyntax("c#-test")] string code, string? fileName = null, CSharpCompilation? compilation = null)

src/Microsoft.Windows.CsWin32/Generator.Features.cs Outdated Show resolved Hide resolved
@AArnott AArnott force-pushed the OverloadDisambiguation branch from e41f64c to 519a407 Compare January 22, 2025 20:24
@AArnott AArnott force-pushed the OverloadDisambiguation branch from 519a407 to 50032d4 Compare January 22, 2025 20:46
@AArnott AArnott enabled auto-merge January 22, 2025 20:46
@AArnott AArnott merged commit c5a4ec4 into main Jan 22, 2025
3 checks passed
@AArnott AArnott deleted the OverloadDisambiguation branch January 22, 2025 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant