Skip to content

BRO1007: Partial elements should declare an access modifier

Every part of a partial type says its accessibility. Replaces StyleCop SA1205.

Example

Before

public partial class Order
{
}

partial class Order
{
}

After

public partial class Order
{
}

public partial class Order
{
}

Why

A part without a modifier doesn't tell the reader the type's accessibility; it has to be looked up in another file.

How the fix works

The fix writes the type's accessibility as another part declares it, or the default when no part does. It goes before the other modifiers (after attributes).

Configuration

[*.cs]
# The SDK's setting, which BRO1404 and BRO1007 follow:
#   for_non_interface_members (or not set): StyleCop's SA1400/SA1205, as described here (BRO1404 and BRO1007)
#   always: interface members get one too ('public', C# 8 and later)
#   never, omit_if_default: no modifiers are asked for (nothing is reported)
dotnet_style_require_accessibility_modifiers = for_non_interface_members

Not reported

  • file types, and types nested in interfaces. That includes a part without file of a file type (file partial class X + partial class X): an access modifier there doesn't compile (CS9052).

Compared with StyleCop

Same positions and output.