Repository navigation
feat!: provide equivalency members from a registry instead of reflection - #1081
Merged
Merged
Conversation
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`.
Contributor
`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.
|
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`.
This was referenced Oct 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Equivalency enumerates members with
Type.GetFields/GetPropertiesand 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.TypeMetadataRegistrylets 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.
MemberToIgnoreloses itsMemberInfoparameter, 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, soIgnoringFieldsandIgnoringPropertiesreplace 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.RegisterEventand 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 anotherCoreOnlycycle each.BuildScopeis set toCoreOnly, becauseaweXpectcompiles against the releasedaweXpect.CoreoutsideDebugand cannot yet see the newMemberToIgnoreshape. Reset it onceaweXpect.Coreis released and the pin is bumped.BREAKING CHANGE:
MemberToIgnore.IgnoreMemberno longer receives aMemberInfo, and theIgnoringoverload that exposed one is replaced byIgnoringFieldsandIgnoringProperties.