Skip to content

CA1860 Does not apply to inherited Length/Count/IsEmpty properties #7368

Open
@omsmith

Description

@omsmith

Analyzer

Diagnostic ID: CA1860

Describe the improvement

An interface such as IReadOnlyList<> inherits its Count property from IReadOnlyCollection<>.

I believe it makes sense for the CA1860 diagnostic to apply to these types as well?

Describe suggestions on how to achieve the rule

Update the HasEligible*Property methods to also inspect AllInterfaces / BaseTypes, similar to the UseCountProperly analyzer.

Additional context

namespace Test;

public class Class1 {
	public void Foo() {
		IReadOnlyList<int> list = [];
		IReadOnlyCollection<int> collection = list;

		if( list.Any() || collection.Any() ) {
			return;
		}
	}
}

image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions