Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
72 lines (56 sloc) 1.64 KB

SA1500

TypeName SA1500BracesForMultiLineStatementsMustNotShareLine
CheckId SA1500
Category Layout Rules

Cause

The opening or closing brace within a C# statement, element, or expression is not placed on its own line.

Rule description

A violation of this rule occurs when the opening or closing brace within a statement, element, or expression is not placed on its own line. For example:

public object Method()
{
    lock (this) {
        return this.value;
    }
}

When StyleCop checks this code, a violation of this rule will occur because the opening brace of the lock statement is placed on the same line as the lock keyword, rather than being placed on its own line, as follows:

public object Method()
{
    lock (this) 
    {
        return this.value;
    }
}

A violation will also occur if the closing brace shares a line with other code. For example:

public object Method()
{
    lock (this) 
    {
        return this.value; }
}

How to fix violations

To fix a violation of this rule, ensure that both the opening and closing braces are placed on their own line, and do not share the line with any other code, other than comments.

How to suppress violations

[SuppressMessage("StyleCop.CSharp.LayoutRules", "SA1500:BracesForMultiLineStatementsMustNotShareLine", Justification = "Reviewed.")]
#pragma warning disable SA1500 // BracesForMultiLineStatementsMustNotShareLine
#pragma warning restore SA1500 // BracesForMultiLineStatementsMustNotShareLine
You can’t perform that action at this time.