Skip to content

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

Merged
AArnott merged 1 commit intomainfrom
OverloadDisambiguation
Jan 22, 2025
Merged

Use C# 13 overload resolution attribute to improve friendly overloads#1336
AArnott merged 1 commit intomainfrom
OverloadDisambiguation

Conversation

@AArnott
Copy link
Copy Markdown
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
Copy Markdown

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)

@AArnott AArnott force-pushed the OverloadDisambiguation branch from e41f64c to 519a407 Compare January 22, 2025 20:24
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.

2 participants