Skip to content

Emit fully qualified type constraints for generic interfaces #75

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

Conversation

simonmckenzie
Copy link
Contributor

@simonmckenzie simonmckenzie commented Apr 6, 2025

This addresses #74, where generic interface type constraints were not being fully qualified, which could result in failure to resolve references within generated interfaces.

  • Move generic interface definition tests into a new file
  • Use RoslynExtensions to generate type constraints, as we do for method type constraints
  • Add test for generation of an interface with base class type constraints
  • Remove custom GetFullTypeString method from RoslynExtensions - the same result is produced by using ToDisplayString.
    -Add test for new() constraint, update logic to ensure that new() is always last

@simonmckenzie simonmckenzie force-pushed the fix/fully-qualify-generic-interface-type-parameters branch from 9df6448 to 88a18c3 Compare April 6, 2025 01:12
- Use RoslynExtensions to generate type constraints, as we do for method type constraints
- Move generic interface definition tests into a new file
- Add test for generation of an interface with base class type constraints
- Remove custom `GetFullTypeString` method from RoslynExtensions - the same result is produced by using `ToDisplayString`.
@simonmckenzie simonmckenzie force-pushed the fix/fully-qualify-generic-interface-type-parameters branch from 88a18c3 to 006cbdb Compare April 6, 2025 01:15
@simonmckenzie simonmckenzie force-pushed the fix/fully-qualify-generic-interface-type-parameters branch from 57dc473 to 6b03b55 Compare April 6, 2025 01:48
var constraints = "";

var isFirstConstraint = true;
var constraints = new List<string>();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I refactored this to emit the new() constraint last.

https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/new-constraint

When you use the new() constraint with other constraints, it must be specified last

@ChristianSauer ChristianSauer merged commit 802c180 into codecentric:master Apr 7, 2025
3 checks passed
@ChristianSauer
Copy link
Collaborator

Thanks, that looks very good!

@simonmckenzie simonmckenzie deleted the fix/fully-qualify-generic-interface-type-parameters branch April 7, 2025 22:58
ChaseFlorell added a commit to ChaseFlorell/net_automatic_interface that referenced this pull request Apr 23, 2025
…tion is properly referenced on the autogenerated interfaces
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants