Skip to content

feat!: provide equivalency members from a registry instead of reflection - #1081

Merged
vbreuss merged 5 commits into
mainfrom
feat/type-metadata-registry
Sep 13, 2026
Merged

vbreuss merged 5 commits into
mainfrom
feat/type-metadata-registry

Conversation

@vbreuss

@vbreuss vbreuss commented Sep 13, 2026 •

Copy link
Copy Markdown
Member

Equivalency enumerates members with Type.GetFields/GetProperties and then fetches them by name, which trimming and Native AOT cannot preserve: the members are removed and the comparison silently verifies less than it claims to. TypeMetadataRegistry lets them be provided statically instead, and the comparison now prefers a registration, reflecting only over types that have none.

Only public members are registered. The equivalency options arrive as a callback that a generator cannot inspect, so it can never emit exactly the members a call site will ask for. Asking a registered type for internal or private members therefore throws, because the zero-member guard catches a comparison that finds nothing but not one that merely comes up short.

MemberToIgnore loses its MemberInfo parameter, which no registration can supply. Its only use - in the documented example and in the single test that relied on it - was telling a field from a property, so IgnoringFields and IgnoringProperties replace the overload that exposed it. A kind-scoped rule is consequently no longer asked about collection elements, which are neither a field nor a property.

RegisterEvent and the three marker attributes have no consumer yet. They belong to the same Core surface as the members, and splitting them across releases would cost another CoreOnly cycle each.

BuildScope is set to CoreOnly, because aweXpect compiles against the released aweXpect.Core outside Debug and cannot yet see the new MemberToIgnore shape. Reset it once aweXpect.Core is released and the pin is bumped.

BREAKING CHANGE:
MemberToIgnore.IgnoreMember no longer receives a MemberInfo, and the Ignoring overload that exposed one is replaced by IgnoringFields and IgnoringProperties.

Equivalency enumerates members with `Type.GetFields`/`GetProperties` and then fetches them by name, which trimming and Native AOT cannot preserve: the members are removed and the comparison silently verifies less than it claims to. `TypeMetadataRegistry` lets them be provided statically instead, and the comparison now prefers a registration, reflecting only over types that have none.

Only public members are registered. The equivalency options arrive as a callback that a generator cannot inspect, so it can never emit exactly the members a call site will ask for. Asking a registered type for internal or private members therefore throws, because the zero-member guard catches a comparison that finds nothing but not one that merely comes up short.

`MemberToIgnore` loses its `MemberInfo` parameter, which no registration can supply. Its only use - in the documented example and in the single test that relied on it - was telling a field from a property, so `IgnoringFields` and `IgnoringProperties` replace the overload that exposed it. A kind-scoped rule is consequently no longer asked about collection elements, which are neither a field nor a property.

`RegisterEvent` and the three marker attributes have no consumer yet. They belong to the same Core surface as the members, and splitting them across releases would cost another `CoreOnly` cycle each.

`BuildScope` is set to `CoreOnly`, because `aweXpect` compiles against the released `aweXpect.Core` outside `Debug` and cannot yet see the new `MemberToIgnore` shape. Reset it once `aweXpect.Core` is released and the pin is bumped.

BREAKING CHANGE: `MemberToIgnore.IgnoreMember` no longer receives a `MemberInfo`, and the `Ignoring` overload that exposed one is replaced by `IgnoringFields` and `IgnoringProperties`.
@vbreuss vbreuss self-assigned this Sep 13, 2026
@vbreuss vbreuss added enhancement New feature or request breaking change The changes require a new major version labels Sep 13, 2026
@github-actions

github-actions Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Test Results

    7 files   -     43      7 suites   - 43   1m 37s ⏱️ - 8m 20s
1 489 tests  - 19 233  1 488 ✅  - 19 232  1 💤  - 1  0 ❌ ±0 
8 284 runs   - 99 538  8 283 ✅  - 99 537  1 💤  - 1  0 ❌ ±0 

Results for commit e91ba8b. ± Comparison against base commit d2ca3fb.

♻️ This comment has been updated with latest results.

`IgnoringFields` and `IgnoringProperties` both rendered as `ignore members:`, exactly like the unscoped `Ignoring`, so a failure message could not say whether a predicate had been applied to the fields, to the properties or to both. The two option tests asserted the same text as a result, which means they would also have passed with the two rule types wired the wrong way round.

The seven sites that decide whether a rule applies to the member at hand now share a single `AppliesTo` helper instead of each restating an inline double negative, so a site added later cannot quietly get the polarity wrong.
`RegisterEvent` creates the registry entry for its type, so equivalency treated an event-only registration as a complete member registration, found no fields or properties and hit the zero-member guard instead of reflecting. Only a registered field or property now counts as a member registration.

The probe test registered the assembly-wide anonymous shape with a single `Title` property, which every other test using that shape would have shared. A distinctive property name keeps the registration to this test.

`TypeMetadata.Empty` was a shared mutable instance handed out on a miss; a nullable `out` says the same thing and cannot be polluted.
… of throwing

Once the generator registers every type that reaches a marked call site, the throw would have turned `IncludeMembers.Internal` and `IncludeMembers.Private` into a hard failure in every build, including the untrimmed ones where reflection works as it always did. The registry only promises that public members survive trimming, so the public members come from the registration and the non-public part of the request is reflected over like on an unregistered type.

Under trimming this is best effort for non-public members, exactly as it is for every type today, and a member the trimmer removed is left out of the comparison silently. That is a deliberate trade against failing every untrimmed build.
The visibility filter skipped a member unless it satisfied every requested flag at once, so `IncludeMembers.Public | IncludeMembers.Internal` - the very combination the documentation shows - matched nothing and tripped the zero-member guard. A member now qualifies when it has one of the requested visibilities. Single flags behave as before.
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
30.1% Coverage on New Code (required ≥ 50%)

See analysis details on SonarQube Cloud

@vbreuss
vbreuss merged commit 2c7e824 into main Sep 13, 2026
12 of 13 checks passed
@vbreuss
vbreuss deleted the feat/type-metadata-registry branch September 13, 2026 20:33
vbreuss added a commit that referenced this pull request Sep 15, 2026
…the marked call sites (#1086)

Trimming and Native AOT remove the members equivalency reaches only through reflection, so a comparison silently verifies less than it claims to. #1081 added the registry; this adds the generator that fills it, from the call sites marked with `[RequiresMemberMetadata]`.

- `aweXpect.Frameworks` is renamed to `aweXpect.Generators` and hosts both generators.
- Every equivalency entry point in `aweXpect` and Core carries the marker, enforced by reflection tests.
- The generator walks the marked types' public members transitively, mirrors what the engine compares, and registers them from a module initializer. Types the generated code cannot reference, such as private nested or file-local ones, and members declared as `object` or a base type stay on the reflection path, documented on the equivalency page together with `[assembly: GenerateMetadata]`, which warns with `aweXpect2001` when a named type yields nothing.
- The registry serves public-only comparisons; a request including `Internal` or `Private` members reflects over the whole type.
- A parity test compiles a corpus into the test assembly and feeds the same source to the generator, so the registered member set is checked against reflection. It exposed four reflection-path issues now fixed in Core: indexers are skipped, a `new`-hidden member is taken from the most derived type instead of throwing, a property on the actual side is read only through a public getter, and a getter's exception surfaces unwrapped.

**BREAKING CHANGE:**
`ObjectCountResult.Equivalent` is an extension method whose parameter is named `options` instead of `optionsCallback`, and `EquivalencyExtensions` moved to the `aweXpect` namespace, so `Contains(x).Equivalent()` needs no new `using`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change The changes require a new major version enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant