试图抑制 StyleCop 消息 SA1513:ClosingCurlyBracketMustBeFollowedByBlankLine
我试图抑制特定属性的以下 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.");
}
}
}
我只是做错了什么吗?或者这是不可能的?这是一个很好的规则,只是对我的财产来说无效。
更新
尝试从 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.");
}
}
}
I am trying to suppress the following StyleCop message for a specific property:
SA1513: Statements or elements wrapped in curly brackets must be followed by a blank line.
I am trying to do the following, but it doesn't seem to work:
[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.");
}
}
}
Am I just doing something wrong? Or is this just not possible? It's a good rule, just not valid in my case for a property.
Update
Tried switching from DocumentationRules to LayoutRules ... still not suppressing.
[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.");
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我认为这可能是 StyleCop 的问题。您安装的是哪个版本? 此页面指出:
我刚刚发现我无法抑制任何消息。我使用的安装程序只提供了 4.3 版本。 Codeplex 上的最新版本是 4.4.0.0。确保您安装了该版本。
更新
我一直在做一些检查,我可以抑制 DocumentationRules:
但不能抑制 SpacingRules 或 LayoutRules。然而,我没有发现任何证据表明为什么会出现这种情况。
I think this might be a problem with StyleCop. Which version do you have installed? This page states that:
I've just found that I can't suppress any messages. The installer I used just gives the version as 4.3. The latest version on the Codeplex is 4.4.0.0. Make sure you have that version installed.
Update
I've been doing some checking and I can suppress DocumentationRules:
but not SpacingRules or LayoutRules. However, nothing I've found indicates why this should be the case.
您的抑制使用
Microsoft.StyleCop.CSharp.DocumentationRules
。我认为它应该是Microsoft.StyleCop.CSharp.LayoutRules
。Your suppression uses
Microsoft.StyleCop.CSharp.DocumentationRules
. I think it should beMicrosoft.StyleCop.CSharp.LayoutRules
.适用于最新的 StyleCop。刚刚删除了“微软”。前缀。
works in latest StyleCop. Just removed "Microsoft." prefix.
StyleCop 中有一个错误,让您只能抑制某些类型的规则。该问题将在即将发布的 StyleCop 4.4 中得到修复。
There is a bug in StyleCop that let's you only suppress certain kinds of rules. This will be fixed in StyleCop 4.4, which is due to be released soon.
请仔细阅读 StyleCop 文档以了解如何抑制规则。以下内容在我的代码中起作用:
来自帮助文件:
正如已经提到的,确保您引用正确的规则命名空间。
Be careful to read the StyleCop documentation to figure-out how to suppress a rule. The following worked in my code:
From the help file:
And as already mentioned, make sure you are referencing the correct rules namespace.
只需在 get 块和 set 块之间添加一个空行即可。
这就是您所要做的,添加一个空行,问题就解决了。
Just put a blank line between your get block and your set block.
That's all you have to do, add one blank line and the problem is solved.