TypeName | SA1134AttributesMustNotShareLine |
CheckId | SA1134 |
Category | Readability Rules |
📝 This rule is new for StyleCop Analyzers, and was not present in StyleCop Classic.
An attribute is placed on the same line of code as another attribute or element.
A violation of this rule occurs when two more more attributes are placed on the same line of code, or an attribute is placed on the same line of code as another element.
For example, the following code would produce a violation of this rule:
[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(MyCodeFixProvider))][Shared]
public class MyCodeFixProvider : CodeFixProvider
{
}
The following code would not produce any violations:
[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(MyCodeFixProvider))]
[Shared]
public class MyCodeFixProvider : CodeFixProvider
{
}
A violation of this rule will not occur for attributes placed on parameters or type parameters.
For example, the following code will not produce violations:
public class MyClass<[Foo][Bar] T>
{
public T MyMethod([In][MarshalAs(UnmanagedType.LPWStr)] string value)
{
...
}
}
To fix a violation of this rule, place each attribute on its own line.
#pragma warning disable SA1134 // Attributes should not share line
[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(MyCodeFixProvider))][Shared]
#pragma warning restore SA1134 // Attributes should not share line
public class MyCodeFixProvider : CodeFixProvider
{
}