Skip to content

Latest commit

 

History

History
63 lines (48 loc) · 1.76 KB

File metadata and controls

63 lines (48 loc) · 1.76 KB

SA1649

TypeName SA1649FileNameMustMatchTypeName
CheckId SA1649
Category Documentation Rules

Cause

The file name of a C# code file does not match the first type declared in the file. For generics that are defined as Class1<T> the name of the file needs to be Class1{T}.cs or Class1`1.cs depending on the fileNamingConvention setting. See Configuration.md for more information.

Partial classes are ignored.

Rule description

A violation of this rule occurs when the file name of a C# file does not contain the name of the first type in the file. For example, consider a C# source file named Class1.cs, with the following code:

public class Class2
{
}

A violation of this rule would occur, since the file name is not contain the correct name of the first type in the file. The file should be written as:

public class Class1
{
}

A readonly modifier on the type (for example a readonly struct) or on members inside the first type (such as C# 8 readonly struct members) does not change the expected file name. The analyzer continues to use the identifier of the first non-partial type, so a type declared as public readonly struct Point still belongs in Point.cs.

How to fix violations

To fix a violation of this rule, rename the file to match the name of the first type from the file.

How to suppress violations

[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1649:FileNameMustMatchTypeName", Justification = "Reviewed.")]
#pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName
#pragma warning restore SA1649 // SA1649FileNameMustMatchTypeName