dotnet / dotnet/sdk

`CA1851` add Attribute to annotate IEnumerable-Consumption

Open
#52,874 0 comments 0 reactions 0 assignees View on GitHub
Area-Microsoft.CodeAnalysis.NetAnalyzers untriaged
Dominant language
C#
Stars
3.2k
Forks
1.3k
PR merge metrics
PR metrics pending

Description

### Is your feature request related to a problem? Please describe.

#### Analyzer
"Possible multiple enumerations of IEnumerable collection"
**Diagnostic ID**: [CA1851](https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1851)

### Describe the solution you'd like
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)

Please consider adding an Atttributes for Methods/Parameters/Properties (in case for eg extension Members?), 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))

### Additional context

- Using `assume_method_enumerates_parameters = true` does produce too many false positives, where it's not worth to suppress all.
- this is copied from https://github.com/dotnet/roslyn-analyzers/issues/7463

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.