Skip to content

BRO1403: Remove delegate parenthesis when possible

delegate { } instead of delegate() { }. Replaces StyleCop SA1410.

Example

root = true

[*.cs]
dotnet_diagnostic.BRO1125.severity = none

Before

using System;

public class Timer
{
    public Action OnTick = delegate() { };
}

After

using System;

public class Timer
{
    public Action OnTick = delegate { };
}

Why

Empty parentheses add nothing: an anonymous method without a parameter list already fits any delegate.

How the fix works

The parentheses are removed. Where BRO1125 is on (the preset), it turns the anonymous method into a lambda instead, so this rule only reports what BRO1125 leaves alone; the example turns BRO1125 off.

Not reported

  • Calls where the parentheses pick the overload (Run(Action) and Run(Action<int>)), like StyleCop.
  • Anonymous methods that BRO1125 turns into lambdas.

Compared with StyleCop

StyleCop reports both SA1130 and SA1410 on delegate() { }; StyleBro reports only BRO1125 there, so the two fixes don't edit the same code.