Skip to content
This repository was archived by the owner on Nov 10, 2026. It is now read-only.

feat: allow ignoring compiler-generated members in the public API - #59

Merged
vbreuss merged 1 commit into
mainfrom
feat/public-api-ignore-compiler-generated
Oct 18, 2026
Merged

vbreuss merged 1 commit into
mainfrom
feat/public-api-ignore-compiler-generated

Conversation

@vbreuss

@vbreuss vbreuss commented Oct 18, 2026

Copy link
Copy Markdown
Member

A record is written with every member the compiler synthesizes for it (copy constructor, EqualityContract, Deconstruct, Equals, GetHashCode, PrintMembers, ToString, ==, !=), which bloats the snapshot with members that follow from the record declaration itself.

Ignoring.CompilerGeneratedMembers() leaves out every member whose own symbol is marked [CompilerGenerated]. The compiler marks only the accessors and backing fields of positional properties, auto-properties and field-like events, so these stay, as do the primary constructor and hand-written members, e.g. a user-written ToString() override. This applies to record classes and record structs.

await Expect.That(typeof(Album).Assembly).MatchesPublicApiSnapshot(o => o.Ignoring.CompilerGeneratedMembers());

A record is written with every member the compiler synthesizes for it (copy constructor, `EqualityContract`, `Deconstruct`, `Equals`, `GetHashCode`, `PrintMembers`, `ToString`, `==`, `!=`), which bloats the snapshot with members that follow from the record declaration itself.

`Ignoring.CompilerGeneratedMembers()` leaves out every member whose own symbol is marked `[CompilerGenerated]`. The compiler marks only the accessors and backing fields of positional properties, auto-properties and field-like events, so these stay, as do the primary constructor and hand-written members, e.g. a user-written `ToString()` override. This applies to record classes and record structs.

```csharp
await Expect.That(typeof(Album).Assembly).MatchesPublicApiSnapshot(o => o.Ignoring.CompilerGeneratedMembers());
```
@vbreuss
vbreuss merged commit 3d0c661 into main Oct 18, 2026
11 checks passed
@vbreuss
vbreuss deleted the feat/public-api-ignore-compiler-generated branch October 18, 2026 10:47
@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

🚀 Benchmark Results

Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.5 LTS (Noble Numbat)
AMD EPYC 7763 2.88GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.303
[Host] : .NET 8.0.32 (8.0.32, 8.0.3226.50405), X64 RyuJIT x86-64-v3
DefaultJob : .NET 8.0.32 (8.0.32, 8.0.3226.50405), X64 RyuJIT x86-64-v3

Method Mean Error StdDev Gen0 Allocated
Dummy_aweXpect 130.3 ns 1.62 ns 1.43 ns 0.0229 384 B

@github-actions

Copy link
Copy Markdown

This is addressed in release v0.5.0.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant