Skip to content

single-class-per-file

C#styleno fixdefault: offcsharp/stylecop

Reports a class or record that comes after the first one in a file: more parts of the first class (when it is partial) are not reported. Structs, interfaces, enums and delegates are not counted. No fix.

A file with one class is found by the name of the class, and a change to a class touches one file. A file with several is a place where a class has to be searched for.

To fix, move the class into a file of its own.

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

Enabled by the presets: csharp/stylecop.

Suppress one line with sudsy-disable-next-line single-class-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 SA1402 full