From e34337b0042d5abbbf578d84507ed362ca98a4d0 Mon Sep 17 00:00:00 2001 From: Vita Chumakova Date: Mon, 17 Nov 2025 11:11:14 +0400 Subject: [PATCH] Fix CA1034 diagnostic when extension members are present --- .../ApiDesignGuidelines/NestedTypesShouldNotBeVisible.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.CodeAnalysis.NetAnalyzers/src/Microsoft.CodeAnalysis.NetAnalyzers/Microsoft.CodeQuality.Analyzers/ApiDesignGuidelines/NestedTypesShouldNotBeVisible.cs b/src/Microsoft.CodeAnalysis.NetAnalyzers/src/Microsoft.CodeAnalysis.NetAnalyzers/Microsoft.CodeQuality.Analyzers/ApiDesignGuidelines/NestedTypesShouldNotBeVisible.cs index 55e53fff08df..cacdeb61622e 100644 --- a/src/Microsoft.CodeAnalysis.NetAnalyzers/src/Microsoft.CodeAnalysis.NetAnalyzers/Microsoft.CodeQuality.Analyzers/ApiDesignGuidelines/NestedTypesShouldNotBeVisible.cs +++ b/src/Microsoft.CodeAnalysis.NetAnalyzers/src/Microsoft.CodeAnalysis.NetAnalyzers/Microsoft.CodeQuality.Analyzers/ApiDesignGuidelines/NestedTypesShouldNotBeVisible.cs @@ -76,6 +76,12 @@ public override void Initialize(AnalysisContext context) return; } + // Do not report diagnostic for extension members + if (nestedType.TypeKind == ITypeSymbolExtensions.ExtensionTypeKind) + { + return; + } + // The Framework Design Guidelines (see 4.9 Nested Types) say that it is okay // to expose nested types for advanced customization and subclassing scenarios, // so, following FxCop's implementation of this rule, we allow protected and @@ -148,4 +154,4 @@ private static bool IsDataSetSpecialCase( dataRowType != null && nestedTypeBases.Contains(dataRowType); } } -} \ No newline at end of file +}