Skip to content

single-namespace-per-file

C#styleno fixdefault: offcsharp/stylecop

Reports a namespace that comes after the first one in a file; nested namespaces are reported too. No fix.

A file with one namespace has one place where its names come from. Several namespaces in a file make the meaning of a name depend on where in the file it is read.

To fix, move the later namespaces into files of their own.

Reported
...
namespace N { class Other { void M() {
...
#endregion
} } class B { } struct S { } namespace M { } }
csharp:
lint:
rules:
single-namespace-per-file: warn # off (default), warn, error

Enabled by the presets: csharp/stylecop.

Suppress one line with sudsy-disable-next-line single-namespace-per-file in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
StyleCop SA1403 full