Skip to content

False positive for rule CA1002 on sealed classes #88310

Open
dotnet/roslyn-analyzers
#6729
@EvinWatson

Description

Analyzer

Diagnostic ID: CA1002: Do not expose generic lists

Analyzer source

NuGet Package: Microsoft.CodeAnalysis.NetAnalyzers

Version: 7.0.0

Describe the bug

This rule prevents the use of Generic Lists for inheritance issues, however sealed classes cannot be inherited, so the rule should not apply. I suggest creating an exception for sealed classes.

https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/sealed

Steps To Reproduce

  1. Create a 'sealed' class.
  2. Create a property of type Generic List.
  3. Observe the analyzer give error CA1002.

Expected behavior

Analyzer should not cite CA1002 on sealed classes.

Actual behavior

Analyzer cites CA1002 on sealed classes.

Additional context

None

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Priority:3Work that is nice to havearea-System.Collectionsbugcode-analyzerMarks an issue that suggests a Roslyn analyzerin-prThere is an active PR which will close this issue when it is merged

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions