luboshl / MiniValidationPlus

Validation library based on System.ComponentModel.DataAnnotations with non-nullable reference types support.
MIT License
0 stars 0 forks source link

Fix getting nullability info for property with getter only #18

Closed luboshl closed 1 month ago

luboshl commented 1 month ago

NonNullablePropertyHelper uses NullabilityInfoContext to get info about nullability of the given property. There was used WriteState to get that info. But when property has no setter, WriteState is null.

The fix is to use ReadState instead WriteState, because property has to have getter when it should be validated.

I've created separate commit with failing tests to repro the bug: b6ba1c0e55743304448e6e3522a89c0afca2e445

Tests that fail:

This PR solves #16