Browse pages
LS3003: File Does Not Match Its Primary Type
LS3003 is a compiler check that reports a C# file whose name does not match the type it holds, which sends every reader searching for code that lives somewhere unexpected. This page states what the rule reports, where the warning sits, and how to align the file with its type.
Reference#
What the rule enforces#
LS3003 enforces Match C# files and primary types (litespec/backend/dotnet/naming#match-c-files-and-primary-types). It runs in all five projects. Its category is LiteSpec.Style. It reports a warning and is enabled by default, as the Analyzers overview describes.
What the rule reports#
The rule reports a C# file whose single top-level type has a different name, and every type after the first when a file holds several top-level types. A dotted file name such as Order.Validation.cs matches the part before the first dot, generic arity is ignored, and partial declarations of the same type count once. Only types directly in the compilation unit or a namespace count; nested types never do. The diagnostic sits on the type name.
Failing example#
In a file named Order.cs, this type reports:
namespace Shop.Domain.Orders;
public sealed class Customer { }Passing example#
In a file named Order.cs, this type passes:
namespace Shop.Domain.Orders;
public sealed class Order { }How to fix#
Give the file the name of its one primary top-level type, or split the file so each top-level type has its own file.
Notes#
What the rule ignores#
The rule does not report files with no top-level types. It does not run outside the five projects.