Skip to content

BRO1131: Do not prefix calls with base unless local implementation exists

this.Reset() instead of base.Reset() when the type has no Reset of its own. Replaces StyleCop SA1100.

Example

Before

public class Connection
{
    public void Reset()
    {
    }
}

public class PooledConnection : Connection
{
    public void Return()
    {
        base.Reset();
    }
}

After

public class Connection
{
    public void Reset()
    {
    }
}

public class PooledConnection : Connection
{
    public void Return()
    {
        this.Reset();
    }
}

Why

base. tells the reader that the type overrides or hides the member and deliberately calls the inherited one. When there is nothing to bypass, it sends them looking for an override that doesn't exist.

How the fix works

base becomes this. The rule only reports when this binds to exactly the same member.

When the SDK's dotnet_style_qualification_for_method (or _property, _field, _event, for that kind of member) is false, which is the preset's setting, the fix removes base. instead (Reset()), as long as the plain name means the same member there; a parameter or local with that name keeps this.. base[i] always becomes this[i]. With the key set to true or not set, the fix writes this. like StyleCop.

Not reported

  • The type overrides or hides the member (base.Describe() inside override Describe()): base. is needed.
  • A virtual, abstract or override member in a type that isn't sealed. this.Reset() dispatches virtually, so a derived type's override would run where base.Reset() ran the base implementation. In a sealed type (or a struct) nothing can override it, and it is reported.

Compared with StyleCop

StyleCop also reports the virtual case in types that aren't sealed, and its fix can change which method runs. Otherwise the same positions and output.