Expose nullable reference type metadata across all target frameworks - #174
Merged
dennisdoomen merged 2 commits intoAug 10, 2026
Merged
Conversation
…meterInfo Closes #162 Add a public/internal Nullability enum and GetNullability/IsNullableReference extension methods for PropertyInfo, FieldInfo and ParameterInfo. On net6.0+ this delegates to System.Reflection.NullabilityInfoContext; on net47, netstandard2.0 and netstandard2.1 it reads the compiler-emitted NullableAttribute/NullableContextAttribute metadata directly via a shared NullabilityMetadataReader. Value types (including Nullable<T>) are short-circuited using the existing NullableOrActualType helper. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The fallback attribute-reading logic is only used on frameworks without System.Reflection.NullabilityInfoContext. It was previously compiled unconditionally into every TFM, which meant it showed up as entirely uncovered/unreachable code on net6.0+ builds where the fast path is used instead, dragging down overall coverage. Wrapping the whole type in #if !NET6_0_OR_GREATER excludes it from those builds so coverage tooling no longer counts it there. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
dennisdoomen
enabled auto-merge (squash)
August 10, 2026 15:41
dennisdoomen
deleted the
dennisdoomen-expose-nullable-reference-metadata
branch
August 10, 2026 15:46
dennisdoomen
pushed a commit
that referenced
this pull request
Aug 10, 2026
Resolve conflicts with PR #174 (nullable reference type metadata) by keeping both sets of additions in PropertyInfoExtensions.cs, FieldInfoExtensions.cs, their specs, and README.md.
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.
Closes #162
Summary
Adds a
Nullabilityenum (Unknown,NotNull,Nullable) plusGetNullability()/IsNullableReference()extension methods forPropertyInfo,FieldInfoandParameterInfo, working consistently across all four target frameworks (net47,net6.0,netstandard2.0,netstandard2.1).Implementation
Nullable<T>) short-circuit using the existingNullableOrActualTypehelper:int→NotNull,int?→Nullable.net6.0and later, reference type nullability is determined viaSystem.Reflection.NullabilityInfoContextfor correctness and simplicity.net47,netstandard2.0andnetstandard2.1, a new internalNullabilityMetadataReaderreads the compiler-emittedSystem.Runtime.CompilerServices.NullableAttribute(falling back toNullableContextAttributeon the declaring type, then its ancestors, then the module) to determine the same information. Since these attributes are compiler-internal and emitted per-assembly, they're matched by full type name rather thantypeof(...).IsNullableReference()is a convenience shortcut forGetNullability() == Nullability.Nullable.Tests
Added spec classes covering non-nullable/nullable reference properties, fields and parameters, value types, nullable value types, generic reference types (
List<string>vsList<string>?), and members compiled without a nullable context (Unknown).Validation
dotnet build src\Reflectify\Reflectify.csproj— succeeds for all 4 TFMs.dotnet test tests\Reflectify.Specs\Reflectify.Specs.csproj— all tests pass onnet8.0,net6.0andnet472(thenetcoreapp3.0leg fails locally only because that runtime isn't installed in this environment, which is a pre-existing/unrelated environment limitation).Docs
Updated the "How do I use it?" section of
README.mdto document the new methods.