I am having trouble with the rules of StyleCop SA1503 (CurlyBracketsMustNotBeOmitted).
In my code, I pretty often have a template like this:
public void SomeFunction(string someArg)
{
if (string.IsNullOrEmpty(someArg)) throw new ArgumentNullException("someArg");
}
The rationale for this is to maintain vertical space when performing multiple validation checks on a single argument and / or checking multiple arguments. The logic in such a check is usually simple and concise, as well as for the exception that is thrown.
However i will never write
if (someConditional)
DoSomeStuff();
I would always write
if (someConditional)
{
DoSomeStuff();
}
So in short:
- Use curly braces if the if statement is split across multiple lines
- Do not use curly braces to simply check arguments, etc., which can be easily (and readily) placed on one line
Can StyleCop help me here?