Why
With nullable reference types, teams often have conventions like "all properties of request/response DTOs must be nullable" (everything is optional on the wire) or "domain entities must not expose nullable members" (absence is modeled explicitly). These conventions are invisible to the compiler across a whole module and currently cannot be verified with aweXpect.Reflection at all, because nullability of reference types is only available via attribute metadata (NullableAttribute / NullableContextAttribute), which is tedious to read manually.
Example of the rule this would enable:
await Expect.That(In.AssemblyContaining<MyRequest>()
.Types().WithName("*Request").AsWildcard())
.OnlyHaveNullableMembers();
Proposal
- Assertions on type collections:
OnlyHaveNullableMembers() and OnlyHaveNonNullableMembers() (covering fields and properties; for value types this maps to Nullable<T>)
- Optionally, member-level filters/assertions:
WhichAreNullable() / IsNullable() on properties and fields
The implementation needs to combine Nullable<T> detection for value types with the NRT attribute metadata for reference types (NullabilityInfoContext can do this on supported targets; older targets may need a manual fallback or reduced support).
The failure message should list the members that violate the expected nullability.
Why
With nullable reference types, teams often have conventions like "all properties of request/response DTOs must be nullable" (everything is optional on the wire) or "domain entities must not expose nullable members" (absence is modeled explicitly). These conventions are invisible to the compiler across a whole module and currently cannot be verified with aweXpect.Reflection at all, because nullability of reference types is only available via attribute metadata (
NullableAttribute/NullableContextAttribute), which is tedious to read manually.Example of the rule this would enable:
Proposal
OnlyHaveNullableMembers()andOnlyHaveNonNullableMembers()(covering fields and properties; for value types this maps toNullable<T>)WhichAreNullable()/IsNullable()on properties and fieldsThe implementation needs to combine
Nullable<T>detection for value types with the NRT attribute metadata for reference types (NullabilityInfoContextcan do this on supported targets; older targets may need a manual fallback or reduced support).The failure message should list the members that violate the expected nullability.