【问题标题】:How to suppress stylecop error SA1650 (incorrectly spelled words)如何抑制 stylecop 错误 SA1650(拼写错误的单词)
【发布时间】:2025-11-03 22:10:02
【问题描述】:

我有一个类的文档标题,其中包含根据 stylecop 拼写不正确的单词。不过,它们是特定于代码的,需要存在。

错误 SA1650:CSharp.Documentation:文档文本 摘要标签包含拼写错误的单词:...

我希望抑制错误。我该怎么做?

【问题讨论】:

  • 你试过这个答案*.com/questions/3287656/…吗?
  • 这是一个不同的 stylecop 错误,我想知道如何抑制这个特定的消息
  • 您必须将答案中的值替换为您自己的值。我认为第一个参数类似于 CSharp.Documentation 或 Microsoft,StyleCop.CSharp.Documentation。第二个是 SA1650:ElementDocumentationMustBeSpelledCorrectly
  • 刚刚找到的值,已经作为答案了

标签: c# documentation stylecop


【解决方案1】:

对我有用的解决方案是添加带有以下参数的[SuppressMessage(...)] 属性:

// using System.Diagnostics.CodeAnalysis;

/// <summary>
/// ... documentation with misspelled words ...
/// </summary>
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1650:ElementDocumentationMustBeSpelledCorrectly", Justification = "Reviewed.")]
public class Program
{
    // ...
}

【讨论】:

    【解决方案2】:

    使用SuppressMessage 来禁止针对特定域的字词发出警告是一种解决方案。但是,您需要将属性添加到包含这些单词的所有方法中。

    恕我直言,最好实现自定义字典,以便分析器忽略这些单词的所有实例并且永远不会生成警告。

    https://msdn.microsoft.com/en-us/library/bb514188.aspx 描述了添加自定义字典的过程——见文末,特别注意构建动作。本文还介绍了 XML 的结构以及如何解决特定警告。

    【讨论】:

    • 您的答案指向 FxCop 的文档。但是,这里的问题是 StyleCop 问题。下面来自 StyleCop 文档的评论有帮助:The CustomDictionary.xml file should be placed in the same folder as the StyleCop.dll and the Rules. That folder (and all subfolders) are checked for the dictionary files. StyleCop loads CustomDictionary.xml, CustomDictionary.en-GB.xml and then CustomDictionary.en.xml (where en-GB is the culture specified in the Settings.StyleCop file).github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/…
    • @RinoTom 移动手指写道;并且,有了令状,继续前进……或者正如法国人所说的“变化越多,它们就越保持不变”
    最近更新 更多