Skip to content

BRO1402: Attribute constructor should not use unnecessary parenthesis

[Obsolete] instead of [Obsolete()]. Replaces StyleCop SA1411.

Example

Before

using System;

[Serializable()]
public class Settings
{
    [Obsolete()]
    public void Reset()
    {
    }
}

After

using System;

[Serializable]
public class Settings
{
    [Obsolete]
    public void Reset()
    {
    }
}

Why

Empty parentheses on an attribute add nothing; without them the attribute reads like the marker it is.

How the fix works

The fix removes the empty parentheses and any space before or inside them.

Not reported

  • A comment inside the parentheses ([Obsolete(/* later */)]).

Compared with StyleCop

Same positions as StyleCop. StyleCop's fix leaves the space of ( ) behind ([Obsolete ]).