TypeName | SA1519BracesMustNotBeOmittedFromMultiLineChildStatement |
CheckId | SA1519 |
Category | Layout Rules |
📝 This rule is new for StyleCop Analyzers, and was not present in StyleCop Classic.
The opening and closing braces for a multi-line C# statement have been omitted.
A violation of this rule occurs when the opening and closing braces for a multi-line statement have been
omitted. In C#, some types of statements may optionally include braces. Examples include if
, while
, and
for
statements. For example, an if
-statement may be written without braces:
if (true)
return
this.value;
Although this is legal in C#, StyleCop requires the braces to be present when the statement spans multiple lines, to increase the readability and maintainability of the code.
To fix a violation of this rule, the violating statement will be converted to a block statement.
if (true)
#pragma warning disable SA1519 // Braces should not be omitted from multi-line child statement
return
this.value;
#pragma warning restore SA1519 // Braces should not be omitted from multi-line child statement