简体   繁体   English

多线卷曲括号的StyleCop规则

[英]StyleCop Rule for Multiline Curly Brackets

SA1503 in StyleCop is an all or nothing deal when it comes to curly brackets. StyleCop中的SA1503在大括号中是一个全有或全无的交易。 I want to be able to allow the following code: 我希望能够允许以下代码:

if (x == 3) return true;

But disallow the following: 但不允许以下内容:

if (x == 3)
    return true;

if (x == 3)
    foreach (var w in widgets)
        x++;

So basically, same line without curly brackets good, multi-line without curly brackets bad. 所以基本上,同一行没有花括号好,多行没有花括号坏。

I'm new to writing custom StyleCop rules and I'm struggling with where to begin. 我是新手编写自定义StyleCop规则而我正在努力从哪里开始。 Any help would be greatly appreciated. 任何帮助将不胜感激。

I've wanted the same styles, and had to turn off the rules StatementMustNotBeOnSingleLine and CurlyBracketsMustNotBeOmitted to support it. 我想要相同的样式,并且必须关闭规则StatementMustNotBeOnSingleLineCurlyBracketsMustNotBeOmitted来支持它。 This now supports the single line scenario, but unfortunately doesn't check the multi line scenario. 这现在支持单行方案,但遗憾的是不检查多行方案。

However I don't think this should be a new rule, but rather a change to the current rules (maybe configurably controlled). 但是我不认为这应该是一个新规则,而是对当前规则的改变(可能是可配置控制的)。 I suggest raising an issue on the StyleCop site , and if you're game get the source and make the change. 我建议在StyleCop网站上提出一个问题,如果你是游戏获取并进行更改。 There is a developer guide in the documentation which will help get you started. 文档中有一个开发人员指南 ,可帮助您入门。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM