TypeName | SA1133DoNotCombineAttributes |
CheckId | SA1133 |
Category | Readability Rules |
📝 This rule is new for StyleCop Analyzers, and was not present in StyleCop Classic.
Two or more attributes appeared within the same set of square brackets.
A violation of this rule occurs two or more attributes are placed within the same set of square brackets.
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 within its own set of square brackets.
[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(MyCodeFixProvider)),
#pragma warning disable SA1133 // Do not combine attributes
Shared]
#pragma warning restore SA1133 // Do not combine attributes
public class MyCodeFixProvider : CodeFixProvider
{
}