Skip to content

CA1860 should be reported for derived types as well #50398

@Alex-Sob

Description

@Alex-Sob

PreferLengthCountIsEmptyOverAnyAnalyzer reports 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:

public class CustomList<T> : List<T> { }

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    untriagedRequest triage from a team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions