试图压制StyleCop消息SA1513:ClosingCurlyBracketMustBeFollowedByBlankLine

mat*_*uma 5 c# stylecop

我试图压缩特定属性的以下StyleCop消息:

SA1513: Statements or elements wrapped in curly brackets must be followed by a blank line.
Run Code Online (Sandbox Code Playgroud)

我正在尝试执行以下操作,但它似乎不起作用:

    [SuppressMessage("Microsoft.StyleCop.CSharp.DocumentationRules", "SA1513:ClosingCurlyBracketMustBeFollowedByBlankLine", Justification = "There are no issues with this code")]
    public string CustomerId
    {
        get
        {
            return this.GetProperty(CustomerIdProperty);
        }
        set
        {
            if (this.IsNew)
            {
                this.SetProperty(CustomerIdProperty, value);
            }
            else
            {
                throw new ReadOnlyException("Id value can only be changed for a new record.");
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

我只是做错了吗?或者这是不可能的?这是一个很好的规则,就我的财产而言无效.

更新

尝试从DocumentationRules切换到LayoutRules ...仍然没有抑制.

    [DataObjectField(true, false)]
    [SuppressMessage("Microsoft.StyleCop.CSharp.LayoutRules", "SA1513:ClosingCurlyBracketMustBeFollowedByBlankLine", Justification = "There are no issues with this code")]
    public string CustomerId
    {
        get
        {
            return this.GetProperty(CustomerIdProperty);
        }
        set
        {
            if (this.IsNew)
            {
                this.SetProperty(CustomerIdProperty, value);
            }
            else
            {
                throw new ReadOnlyException("Id value can only be changed for a new record.");
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

Chr*_*isF 3

我认为这可能是 StyleCop 的问题。您安装的是哪个版本?该页面指出:

从 StyleCop 4.3.2 开始,可以通过在源代码中添加抑制属性来抑制规则违规的报告。

我刚刚发现我无法抑制任何消息。我使用的安装程序只提供了 4.3 版本。Codeplex上的最新版本是 4.4.0.0。确保您安装了该版本。

更新

我一直在做一些检查,我可以抑制 DocumentationRules:

    [SuppressMessage("Microsoft.StyleCop.CSharp.DocumentationRules",
                     "SA1600:ElementsMustBeDocumented",
                     Justification = "Reviewed. Suppression is OK here.")]
Run Code Online (Sandbox Code Playgroud)

但不是 SpacingRules 或 LayoutRules。然而,我没有发现任何证据表明为什么会出现这种情况。