[API Proposal]: Reflecting to find nullability of a generic return type is unreasonably complicated #110971
Labels
api-suggestion
Early API idea and discussion, it is NOT ready for implementation
area-System.Reflection
untriaged
New issue has not been triaged by the area owner
Background and motivation
For my specific problem, I am trying to recursively walk each member of an object to see if a non-nullable type has had null assigned.
E.g.
Which has been a blast to write, until I encountered Index Properties - specifically generic index properties, which always claim to be allowed to return null.
Quite probably I'm just missing something, but I'm missing something because this API is currently less than intuitive.
First, I'd love to replace this:
with:
Once I have the index property, next step looks like:
Which only works for non-generic index properties. Try this on e.g. a
var l = new List<string>()
and it'll happily say thatl[2]
can return null.API Proposal
I'm hoping for two things here
NullabilityInfoContext.Create(PropertyInfo)
expanded to also assess nullability of generic index propertiesNullabilityInfo
for methods (and property methods) that lets you query nullability in slightly more natural language.API Usage
here
info
with additional members usable like:Alternative Designs
No response
Risks
No response
The text was updated successfully, but these errors were encountered: