代码之家  ›  专栏  ›  技术社区  ›  mattruma

试图抑制stylecop消息sa1513:closingCurlyBracketMustBefollowedByLankline

  •  5
  • mattruma  · 技术社区  · 15 年前

    我试图为特定属性取消显示以下stylecop消息:

    SA1513: Statements or elements wrapped in curly brackets must be followed by a blank line.
    

    我正试着做以下事情,但似乎不起作用:

        [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.");
                }
            }
        }
    

    我只是做错什么了吗?或者这是不可能的?这是一个很好的规则,只是在我的情况下对一个财产无效。

    更新

    尝试从文档规则切换到布局规则…仍然没有压制。

        [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.");
                }
            }
        }
    
    6 回复  |  直到 15 年前
        1
  •  3
  •   ChrisF    14 年前

    我想这可能是StyleCop的问题。您安装了哪个版本? This page 声明:

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

    我刚发现我无法抑制任何信息。我使用的安装程序只给出了4.3版本。上的最新版本 Codeplex 4.4.0.0。请确保已安装该版本。

    更新

    我已经做了一些检查,我可以取消文档规则:

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

    但不是Spacingrules或Layoutrules。然而,我没有发现任何迹象表明为什么会这样。

        2
  •  3
  •   Klaus Byskov Pedersen    15 年前

    你的压制使用 Microsoft.StyleCop.CSharp.DocumentationRules . 我想应该是 Microsoft.StyleCop.CSharp.LayoutRules .

        3
  •  2
  •   Jason Allor    15 年前

    stylecop中有一个bug,让我们只禁止某些类型的规则。这将在StyleCop4.4中修复,StyleCop4.4将很快发布。

        4
  •  2
  •   Todd M. Taylor    14 年前

    请仔细阅读stylecop文档以了解如何抑制规则。以下代码适用于我的代码:

        [SuppressMessage("Microsoft.StyleCop.CSharp.MaintainabilityRules",
        "SA1402:FileMayOnlyContainASingleClass",
        Justification = "Splitting this file into classes would get too confusing.")]
    

    从帮助文件:

    suppressMessage属性的格式如下:

    [suppressMessage(“规则类别”、“规则ID”、“对正”)]

    哪里:

    • 规则类别 -定义规则的stylecop规则命名空间。例如, microsoft.stylecop.csharp.documentationrules文档规则

    • 规则ID -规则的标识符,格式为shortname:longname。

      例如,SA1600:elementsmustbedocumented

    • 正当理由 -用于记录抑制原因的文本 消息。

    如前所述,确保引用的规则命名空间正确。

        5
  •  2
  •   Anatoly Zhmur    10 年前
    [SuppressMessage("StyleCop.CSharp.LayoutRules", "SA1513:ClosingCurlyBracketMustBeFollowedByBlankLine", Justification = "There are no issues with this code")]
    

    最新款式的。刚刚删除了“microsoft.”前缀。

        6
  •  -2
  •   Task    14 年前

    在你的get块和set块之间放一个空行。
    这就是你要做的,加上一个空行,问题就解决了。