Skip to content

Latest commit

 

History

History
59 lines (45 loc) · 1.31 KB

SA1127.md

File metadata and controls

59 lines (45 loc) · 1.31 KB

SA1127

TypeName SA1127GenericTypeConstraintsMustBeOnOwnLine
CheckId SA1127
Category Readability Rules

📝 This rule is new for StyleCop Analyzers, and was not present in StyleCop Classic.

Cause

A generic constraint on a type or method declaration is on the same line as the declaration, within a C# code file.

Rule description

A violation of this rule occurs whenever the code contains one or more where clauses containing generic type constraints on the same line as the type or method declaration itself.

For example, the following code would produce two violations of this rule:

private void Method<T, R>() where T : class where R : class, new()
{
}

The following code would not produce any violations:

private void Method<T, R>()
    where T : class
    where R : class, new()
{
}

How to fix violations

To fix a violation of this rule, move each where clause to its own line.

How to suppress violations

#pragma warning disable SA1127 // Generic type constraints should be on their own line
private void Method<T>() where T : class
#pragma warning restore SA1127 // Generic type constraints should be on their own line
{
    // method body...
}