dotnet / dotnet/sdk

CA1860 should be reported for derived types as well

Open
#50,398 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

`PreferLengthCountIsEmptyOverAnyAnalyzer` reports [CA1860](https://learn.microsoft.com/en-gb/dotnet/fundamentals/code-analysis/quality-rules/ca1860) error only if the type itself has `IsEmpty`/`Count`/`Length` property, and the error is not reported for a type that is derived from another type with one of those properties, e.g. a custom collection type.

For example:

```cs
public class CustomList : List { }

public class Test
{
public void M()
{
// CA1860 is not reported
_ = new CustomList().Any();
}
}
```

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.