gpt4 book ai didi

c# - StyleCop.Analyzers 是否支持 C# 记录?

转载 作者:行者123 更新时间:2023-12-02 01:46:35 24 4
gpt4 key购买 nike

问题描述:

在使用StyleCop.Analyzers 的项目中添加C# 记录时,显示警告:

Warning AD0001  Analyzer 'StyleCop.Analyzers.DocumentationRules.SA1649FileNameMustMatchTypeName' threw an exception of type 'System.ArgumentException' with message 'Unhandled declaration kind: RecordDeclaration'.    

System.ArgumentException: Unhandled declaration kind: RecordDeclaration
at StyleCop.Analyzers.Helpers.NamedTypeHelpers.GetNameOrIdentifier(MemberDeclarationSyntax member)
at StyleCop.Analyzers.Helpers.FileNameHelpers.GetConventionalFileName(MemberDeclarationSyntax declaration, FileNamingConvention convention)
at StyleCop.Analyzers.DocumentationRules.SA1649FileNameMustMatchTypeName.Analyzer.HandleSyntaxTree(SyntaxTreeAnalysisContext context, StyleCopSettings settings)
at StyleCop.Analyzers.AnalyzerExtensions.<>c__DisplayClass0_0.<RegisterSyntaxTreeAction>b__0(SyntaxTreeAnalysisContext c)
at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c.<ExecuteSyntaxTreeActionsCore>b__59_1(ValueTuple`2 data)
at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info)

它是 StyleCop.Analyzers 中的错误吗?

重现步骤:

  • 创建一个新的 .Net6 控制台项目(甚至 .Net5)。

  • 在其中添加一条C#记录:public record Member(string FirstName, string LastName);

  • 安装包 StyleCop.Analyzers v1.1.118

  • 查看 Visual Studio 错误列表,您将看到警告。

最佳答案

谢谢@stuartd,你为我指明了正确的方向。

确实是 Stylecop 1.1.X 的一个 bug

已在 StyleCop.Analyzers.Unstable v1.2.0-beta.161 中更正.但不幸的是,它还没有包含在稳定版本中。所以我现在看到的解决方法是使用不稳定的版本

关于c# - StyleCop.Analyzers 是否支持 C# 记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70824524/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com