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

CA1851 add Attribute to annotate IEnumerable-Consumption #7463

Open
LukasGelke opened this issue Nov 1, 2024 · 0 comments
Open

CA1851 add Attribute to annotate IEnumerable-Consumption #7463

LukasGelke opened this issue Nov 1, 2024 · 0 comments

Comments

@LukasGelke
Copy link

Analyzer

"Possible multiple enumerations of IEnumerable collection"
Diagnostic ID: CA1851

Describe the improvement

https://github.com/dotnet/roslyn-analyzers/blob/main/docs/Analyzer%20Configuration.md#enumeration-methods

As the author of an assembly/NuGet that provides several extensions for a myriad of use cases, I'd like to annotate those who are subject for "multiple enumeration". Currently this is only possible via editorconfig-Options, which cannot be merged/appended, only ever overwritten. Which would make the user to have to add all signatures manually (also every time in the event of a change)

Describe suggestions on how to achieve the rule

Add Atttributes for Methods/Parameters, that would put them in the same list as enumeration_methods and linq_chain_methods, or the already hardcoded Linq-Extensions.

For backporting reasons, the analyzer should expect the Attribute (via FullName) to exist in multiple Assemblies. (aka compilation.GetTypesByMetadataName(...) (plural)) (Because the Analyzer-NuGet should not be a Runtime-Dependency)

Additional context

Using assume_method_enumerates_parameters = true does produce too many false positives, where it's not worth to suppress all.

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