feat: add nullability filters and assertions for members#332
Merged
Conversation
🚀 Benchmark ResultsDetails
|
👽 Mutation ResultsaweXpect.ReflectionDetails
The final mutation score is 86.43%Coverage Thresholds: high:80 low:60 break:0 |
Implements #330: - `IsNullable()` / `IsNotNullable()` on single properties and fields - `AreNullable()` / `AreNotNullable()` on property and field collections - `WhichAreNullable()` / `WhichAreNotNullable()` filters for properties and fields - `OnlyHasNullableMembers()` / `OnlyHasNonNullableMembers()` on single types - `OnlyHaveNullableMembers()` / `OnlyHaveNonNullableMembers()` on type collections - `WhichOnlyHaveNullableMembers()` / `WhichOnlyHaveNonNullableMembers()` type filters Nullability covers `Nullable<T>` value types and nullable reference types. Detection uses `NullabilityInfoContext` on .NET 8+ and falls back to reading the `NullableAttribute` / `NullableContextAttribute` metadata on netstandard2.0.
Decode the NullableAttribute / NullableContextAttribute metadata on every target framework instead of using NullabilityInfoContext on .NET 8+, so the same member yields the same result everywhere. This fixes two cross-framework divergences found in review: - [AllowNull] / [MaybeNull] post-condition attributes made members count as nullable on .NET 8+ but not on netstandard2.0 - unconstrained generic type parameters (T) counted as nullable on .NET 8+ but not on netstandard2.0 Also partition members in a single pass in the OnlyHas… type constraints and pin the edge-case semantics (arrays, indexers, generics, post-condition attributes) with tests.
- resolve members declared as a bare generic type parameter through the constructed base type, so that e.g. a member of type T accessed via a type deriving from Base<string?> counts as nullable - fail AreNotNullable for null entries in the collection, consistent with AreNotStatic/AreNotReadOnly and the singular IsNotNullable - add optional MemberScope parameter to OnlyHas(Non)NullableMembers, OnlyHave(Non)NullableMembers and WhichOnlyHave(Non)NullableMembers - mark NullableWriteOnlyProperty test helpers as static and suppress CS0436 for the Nullable polyfill in the internal test project (sonar)
69b9c77 to
fe45383
Compare
|
|
This is addressed in release v2.0.0. |
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.

IsNullable()/IsNotNullable()on single properties and fieldsAreNullable()/AreNotNullable()on property and field collectionsWhichAreNullable()/WhichAreNotNullable()filters for properties and fieldsOnlyHasNullableMembers()/OnlyHasNonNullableMembers()on single typesOnlyHaveNullableMembers()/OnlyHaveNonNullableMembers()on type collectionsWhichOnlyHaveNullableMembers()/WhichOnlyHaveNonNullableMembers()type filtersNullability covers
Nullable<T>value types and nullable reference types.Detection uses
NullabilityInfoContexton .NET 8+ and falls back to readingthe
NullableAttribute/NullableContextAttributemetadata on netstandard2.0.