Permalink
Fetching contributors…
Cannot retrieve contributors at this time
59 lines (45 sloc) 1.31 KB

SA1501

TypeName SA1501StatementMustNotBeOnSingleLine
CheckId SA1501
Category Layout Rules

Cause

A C# statement containing opening and closing braces is written completely on a single line.

Rule description

A violation of this rule occurs when a statement that is wrapped in opening and closing braces is written on a single 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 entire lock statement is written on one line. The statement should be written across multiple lines, with the opening and closing braces each on their own line, as follows:

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

How to fix violations

To fix a violation of this rule, rewrite the statement so that it expands across multiple lines.

How to suppress violations

[SuppressMessage("StyleCop.CSharp.LayoutRules", "SA1501:StatementMustNotBeOnSingleLine", Justification = "Reviewed.")]
#pragma warning disable SA1501 // StatementMustNotBeOnSingleLine
#pragma warning restore SA1501 // StatementMustNotBeOnSingleLine