tags:

views:

30

answers:

1

Hi,

Is it possible to get StyleCop to say that this is the correct way to use curly braces?

if (request.Query == string.Empty) {
    return SearchResponse.Empty;
}

But not this

if (request.Query == string.Empty)
    return SearchResponse.Empty;

Or this:

if (request.Query == string.Empty)
{
    return SearchResponse.Empty;
}

I also want this behavior for if, else, else if, while, foreach and for. But not for class declarations or method declarations.

+2  A: 

I don't think it does that out of the box; however, StyleCop ships with an SDK that includes instructions on how to author custom rules. Although it would be most helpful if someone has already created a custom rule accomplishing what you describe, you may find that you must roll your own.

I was going to add a link to the SDK docs, but the .CHM appeared to be broken at the time. You may need to get the whole project from http://stylecop.codeplex.com to read up on details.

Good luck!

kbrimington
Thank you! I`ll look into it when I have some spare time. I hope it´s an easy SDK so that I can accomplish it without too much effort. :-)
Binary255