BRO1114: Do not combine fields¶
Every field (and event field) has a declaration of its own. Replaces StyleCop SA1132.
Example¶
Before¶
using System;
public class Point
{
private int x, y;
[Obsolete("Use Label.")]
public string name = string.Empty, title = string.Empty;
}
After¶
using System;
public class Point
{
private int x;
private int y;
[Obsolete("Use Label.")]
public string name = string.Empty;
[Obsolete("Use Label.")]
public string title = string.Empty;
}
Why¶
A combined declaration hides the second field at the end of a line, and a change to one field's type or modifiers changes all of them.
How the fix works¶
Each field gets its own declaration with the same attributes, modifiers and type, and the same documentation comment
if there is one, in the same order (initializers keep running in the same order). Event fields, and a field that spans
several lines from the next, are separated by a blank line, which BRO1505 wants between them. A
documented field's copies are too, which BRO1513 wants above each documentation comment. Local variables (int a, b; in a method) aren't reported, like
in StyleCop.
Not reported¶
- A comment inside the declaration (
int a, /* note */ b;). - A declaration that shares its first line with other code.
Compared with StyleCop¶
Same positions as StyleCop. StyleCop's fix keeps the attributes on the first field only, so the others lose them
(in the example, title would no longer be obsolete), and keeps the documentation on one field.