Skip to content

Fix S2743 FN: Static fields of nested class inside generic class #4081

@csaba-sagi-sonarsource

Description

@csaba-sagi-sonarsource

Description

No issue is raised for static nested class fields that are not shared among instances of different close constructed types. (S2743)

Repro steps

        public class StaticFieldInGenericClass<T>
            where T : class
        {
            public static T tProp { get; set; }

            internal string NestedClassUsage => NestedClass.StringField;

            private static class NestedClass
            {
                public static readonly string StringField = "String"; // FN
            }
        }

Expected behavior

Issues are reported for the fields of the static nested class as they are not shared among instances of different close constructed types.

Actual behavior

No issues are reported.

Known workarounds

None

Related information

C#/VB.NET Plugins version: 8.18

Metadata

Metadata

Labels

False NegativeRule is NOT triggered when it should be.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions