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

Recognized other "curiously recurring template pattern" (CRTP) interfaces #7591

Open
manfred-brands opened this issue Feb 28, 2025 · 0 comments

Comments

@manfred-brands
Copy link
Contributor

Analyzer

Diagnostic ID: CA2260

Describe the improvement

The implementation of the rule has a hard-coded list of interfaces it knows.

If a developer implements an extra interface also following CRTP it currently would need to write its own analyzer.
It would be nice if the existing rule would either automatically recognize CRTP interfaces or allow configuring additional recognizable interfaces.

Describe suggestions on how to achieve the rule

I see three options:

  • Recognize CRTP interfaces where a generic parameter is constraint by itself.
    • Most flexible but could be expensive as the same interface will be analyzed multiple times unless we have a caching capability in the compilation context.
  • Recognize generic parameter name TSelf
    • Could be used as a faster initial detection of CRTP, skipping any generic interfaces where the first parameter has a different name before checking the constraints.
  • Allow specifying additional_interfaces in configuration file.
    • dotnet_diagnostic.CA2260.additional_interfaces: IMyCRTP

Additional context

The auto detection would help if the dotnet runtime adds more CRTP interface definition without the need to update the analyzer rule.

If any of the suggestions are acceptable, I'm happy to contribute and update the analyzer.

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

No branches or pull requests

1 participant