简体   繁体   中英

StyleCop Rule for Multiline Curly Brackets

SA1503 in StyleCop is an all or nothing deal when it comes to curly brackets. 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. 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. 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. There is a developer guide in the documentation which will help get you started.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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