BRO1516: Use braces consistently¶
When one clause of an if/else chain has braces, all of them do. Replaces StyleCop SA1520.
Example¶
Before¶
public class Tariff
{
public decimal Rate(int zone)
{
if (zone == 1)
{
return 0.5m;
}
else
return 1m;
}
}
After¶
public class Tariff
{
public decimal Rate(int zone)
{
if (zone == 1)
{
return 0.5m;
}
else
{
return 1m;
}
}
}
Why¶
A chain that mixes clauses with and without braces is harder to scan, and the clause without braces is the one that gets a second statement by mistake.
How the fix works¶
Like BRO1514.
Not reported¶
- A multi-line clause when BRO1515 is on: that rule reports it (like StyleCop).
- The cases BRO1514 skips.
Compared with StyleCop¶
Same positions and output, apart from the skipped cases.