CA1034 未显示,即使使用 <AnalysisMode>AllEnabledByDefault</AnalysisMode>

问题描述

我创建了 Microsoft 作为示例给出的类:

internal class ParentType
{
    public class NestedType
    {
        public NestedType()
        {
        }
    }

    public ParentType()
    {
        NestedType nt = new();
    }
}

但似乎没有生成警告。我使用的是 Visual Studio 2019。此代码正在测试的框架是 .NET 5

解决方法

警告 CA1034 仅在外部可见嵌套类型上报告,这些嵌套类型在另一个外部可见类型中声明。 由于您的封闭类型是 internal,因此您的嵌套类型也无法从该程序集外部访问,因此不违反规则。

当您也将封闭类型设为 public 时,您将看到正在报告的诊断:

public class ParentType
{
    public class NestedType // Warning CA1034
    {
    }
}

所以我相信你在官方文档的例子中发现了一个错误。

更新:官方文档现在更新了固定的示例代码。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...