Navigation:  StyleCop 4.3 > StyleCop 4.3 Rules > Maintainability Rules >

SA1402: FileMayOnlyContainASingleClass

Previous pageReturn to chapter overviewNext page
StyleCop 4.3

Send comments on this topic.

SA1402: FileMayOnlyContainASingleClass

Glossary Item Box

TypeName
FileMayOnlyContainASingleClass

CheckId

SA1402

Category

Maintainability Rules

 

Cause

A C# code file contains more than one unique class.

Rule Description

A violation of this rule occurs when a C# file contains more than one class. To increase long-term maintainability of the code-base, each class should be placed in its own file, and file names should reflect the name of the class within the file.

It is possible to place other supporting elements within the same file as the class, such as delegates, enums, etc., if they are related to the class.

It is also possible to place multiple parts of the same partial class within the same file.

How to Fix Violations

To fix an instance of this violation, move each class into its own file.

 


© Microsoft Corporation. All Rights Reserved.