簡體   English   中英

StyleCop.Analyzers 是否支持 C# 記錄?

[英]Does StyleCop.Analyzers support C# records?

問題描述:

在帶有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);

  • 安裝 package StyleCop.Analyzers v1.1.118

  • 查看 Visual Studio 錯誤列表,您將看到警告。

謝謝@stuartd,您為我指明了正確的方向。

這確實是 Stylecop 1.1.X 中的一個錯誤

它在StyleCop.Analyzers.Unstable v1.2.0-beta.161中得到糾正。 但不幸的是,它還沒有包含在穩定版本中。 所以我現在看到的解決方法是使用不穩定的版本

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM