You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Review impact of record structs on existing rules #3979
StyleCopAnalyzers: C# 10 record struct Support Audit
C# 10 introduces record struct and readonly record struct types. StyleCopAnalyzers must recognize these as distinct type declarations and apply existing rules consistently.
This audit lists impacted rules, required changes, and test coverage. Rules not mentioned were assessed as unaffected.
SA1201: Elements Must Appear in the Correct Order
Implementation
SA1201 enforces the order of top-level elements and type members.
RecordStructDeclaration nodes are now mapped to the struct category (same as regular struct).
This ensures:
A record struct is ordered alongside struct declarations, not with classes.
Error messages correctly distinguish “record struct” vs “class” when reporting misordering.
Documentation
SA1201 documentation lists the standard ordering (classes, structs, etc.).
It may be worth clarifying that “structs” include record structs.
Tests
Ordering scenarios involving record struct and classes, such as:
Misordered record struct before/after a class.
Messages correctly mentioning “record struct”.
SA1202: Elements Must Be Ordered by Access
Implementation
SA1202 enforces ordering by access level among adjacent members of the same type.
Support was extended to include RecordStructDeclaration in its target syntax kinds.
Result:
Members of a record struct are ordered just like members of a regular struct (e.g., public before internal, etc.).
Documentation
No specific change required, as the concept is the same for all types.
Tests
Extend existing SA1202 tests to include record struct members with differing access modifiers.
SA1205: Partial Elements Must Declare Access
Implementation
SA1205 requires partial type declarations to specify an access modifier.
The analyzer already covers all TypeDeclarationSyntax (class, struct, interface, etc.), and now also includes record class and record struct.
Result:
partial record struct without an access modifier is flagged.
Code fix logic understands the new keywords.
Documentation
Clarify that all partial type declarations (including record types) must declare access.
Optionally add an example using partial record struct.
Tests
Valid example:
publicpartialrecordstructFoo;
– no SA1205 diagnostic.
Invalid example:
partialrecordstructFoo;
– SA1205 diagnostic expected.
SA1300: Element Must Begin with Uppercase Letter
Implementation
SA1300 enforces PascalCase for type names (classes, structs, interfaces, etc.).
The analyzer now registers for RecordStructDeclaration along with other type declarations.
Result:
record struct exampleRecord is flagged by SA1300.
record struct ExampleRecord is accepted.
Documentation
Existing text already applies to “type names”.
Optionally mention that record types are included for clarity.
Tests
Add tests ensuring record struct names obey the uppercase-first rule.
SA1313: Parameter Names Must Begin with Lowercase Letter
Implementation
SA1313 expects parameters to be camelCase, but C# records use PascalCase positional parameters in primary constructors because they become properties.
Previously, SA1313 exempted primary constructor parameters on record classes.
It now also exempts primary constructor parameters on record structs by checking when a parameter’s parent is a RecordDeclaration or RecordStructDeclaration.
Result:
For:
publicrecordstructPoint(intX,intY);
SA1313 does not report diagnostics on X and Y.
Documentation
Documentation should mention that positional record parameters (for both record classes and record structs) are allowed to be PascalCase.
Tests
Regression tests for the issue where SA1313 was incorrectly emitted for record struct parameters.
Examples like:
publicrecordstructPoint(intX,intY);
must pass without SA1313 diagnostics.
SA1402: File May Only Contain a Single Type
Implementation
SA1402 can be configured to enforce one type per file for certain categories.
Implementation was updated so that:
Record classes count as “class”.
Record structs count as “struct”.
This resolves a bug where record types were ignored in the file-type counting logic.
Behavior
Under default settings:
A file containing a class and a record struct may be allowed, depending on configuration (structs are often allowed with classes by default).
Under stricter settings:
A file containing a class and a record struct may trigger SA1402 if configuration requires separate files for those categories.
The helper that extracts the type name was extended to handle RecordStructDeclaration.
Result:
Record structs are treated like any other top-level type for SA1649.
record struct MyRecordStruct should live in MyRecordStruct.cs (under default configuration).
Documentation
Clarify that SA1649 applies to:
Classes
Structs
Interfaces
Record classes
Record structs
Tests
Files containing a single record struct:
Matching file name → no SA1649 diagnostic.
Non-matching file name → SA1649 diagnostic.
Ensure no exceptions are thrown when analyzing record structs.
Summary
All of the above rules have been updated to recognize and properly handle record struct and readonly record struct declarations. StyleCopAnalyzers now:
Applies ordering rules consistently,
Enforces naming and file naming expectations,
Handles documentation text correctly,
Avoids crashes on record struct syntax.
Documentation should be reviewed for any references to “classes” or “structs” and updated where necessary to explicitly include record types.
Activity
sharwell commentedon Dec 3, 2025
Audit by Deep Research
StyleCopAnalyzers: C# 10
record structSupport AuditC# 10 introduces
record structandreadonly record structtypes. StyleCopAnalyzers must recognize these as distinct type declarations and apply existing rules consistently.This audit lists impacted rules, required changes, and test coverage. Rules not mentioned were assessed as unaffected.
SA1201: Elements Must Appear in the Correct Order
Implementation
RecordStructDeclarationnodes are now mapped to the struct category (same as regularstruct).This ensures:
record structis ordered alongsidestructdeclarations, not with classes.Documentation
Tests
Ordering scenarios involving
record structand classes, such as:record structbefore/after aclass.SA1202: Elements Must Be Ordered by Access
Implementation
RecordStructDeclarationin its target syntax kinds.Result:
record structare ordered just like members of a regularstruct(e.g.,publicbeforeinternal, etc.).Documentation
Tests
record structmembers with differing access modifiers.SA1205: Partial Elements Must Declare Access
Implementation
TypeDeclarationSyntax(class, struct, interface, etc.), and now also includesrecord classandrecord struct.Result:
partial record structwithout an access modifier is flagged.Documentation
partial record struct.Tests
Valid example:
– no SA1205 diagnostic.
Invalid example:
– SA1205 diagnostic expected.
SA1300: Element Must Begin with Uppercase Letter
Implementation
RecordStructDeclarationalong with other type declarations.Result:
record struct exampleRecordis flagged by SA1300.record struct ExampleRecordis accepted.Documentation
Tests
SA1313: Parameter Names Must Begin with Lowercase Letter
Implementation
RecordDeclarationorRecordStructDeclaration.Result:
For:
SA1313 does not report diagnostics on
XandY.Documentation
Tests
Regression tests for the issue where SA1313 was incorrectly emitted for record struct parameters.
Examples like:
must pass without SA1313 diagnostics.
SA1402: File May Only Contain a Single Type
Implementation
SA1402 can be configured to enforce one type per file for certain categories.
Implementation was updated so that:
This resolves a bug where record types were ignored in the file-type counting logic.
Behavior
Under default settings:
Under stricter settings:
Documentation
Clarify that:
Tests
Dedicated C# 10 tests (e.g.,
SA1402ForRecordStructCSharp10UnitTests) that:SA1642: Constructor Summary Documentation Must Begin with Standard Text
Implementation
SA1642 checks
<summary>documentation for constructors, verifying it starts with standard text:Initially, record structs were misidentified as classes, causing SA1642 to suggest “class” in the message.
The logic was updated so that a constructor whose containing type is a
RecordStructDeclarationis treated as a struct.Result:
Documentation
SA1642 documentation already distinguishes class vs struct phrasing.
Consider adding a note:
Tests
Constructors in record structs with correct vs incorrect summary text:
SA1649: File Name Must Match Type Name
Implementation
SA1649 enforces that when a file contains a single type, the file name must match the type name.
Previously, encountering a
record structcaused an exception:The helper that extracts the type name was extended to handle
RecordStructDeclaration.Result:
record struct MyRecordStructshould live inMyRecordStruct.cs(under default configuration).Documentation
Clarify that SA1649 applies to:
Tests
Files containing a single record struct:
Summary
All of the above rules have been updated to recognize and properly handle
record structandreadonly record structdeclarations. StyleCopAnalyzers now:Documentation should be reviewed for any references to “classes” or “structs” and updated where necessary to explicitly include record types.
Sources
SA1201ElementsMustAppearInTheCorrectOrder.csSA1201CSharp10UnitTests.csSA1202ElementsMustBeOrderedByAccess.csSA1205UnitTests.csSA1300ElementMustBeginWithUpperCaseLetter.csSA1313ParameterNamesMustBeginWithLowerCaseLetter.csSA1402FileMayOnlyContainASingleType.csSA1402ForRecordStructCSharp10UnitTests.csSA1642ConstructorSummaryDocumentationMustBeginWithStandardText.csNamedTypeHelpers.cs