Skip to content

Walk public instance properties only, not static ones - #88

Merged
tgharold merged 3 commits into
masterfrom
tgh-20261002-instance-properties-only
Oct 2, 2026
Merged

tgharold merged 3 commits into
masterfrom
tgh-20261002-instance-properties-only

Conversation

@tgharold

@tgharold tgharold commented Oct 2, 2026

Copy link
Copy Markdown
Owner

Motivation

The validator walked public static properties as well as instance properties, because Type.GetProperties() with no arguments returns both. A static property holds data of the type, not of the model. Validator ignores it, and so does System.Text.Json. The effect was that a shared static object that was invalid failed every model of that type, with an error such as Shared.Name, and a static property that builds a new object on each read needed the equal-ancestor check or the depth limit to stop the walk.

Walking public instance properties only matches what a caller expects from DataAnnotations. It changes results, because a model that failed only because of a static property now passes, so it is marked BREAKING in the changelog.

This is part 3 of 3 small PRs, in this order: root collection (#86), nested class-level error path (#87), instance properties only (this one). This PR is stacked on #87 and targets its branch, so the diff shows only this change. Merge #86 and #87 first. After #87 merges, GitHub retargets this PR to master.

Summary

  • Add GetWalkedProperties, which asks for public instance properties and applies the existing walk rules. The walk and the leaf-type check both use it, so they agree.
  • A static property is no longer walked. Attributes on a static property never ran, and still do not.
  • README and CHANGELOG: the README says that only public instance properties are walked, and the changelog has a BREAKING entry.

Test plan

  • Full suite on net8.0 and net10.0: 588 passed, 7 skipped, 0 failed
  • net481 test project builds with 0 warnings and 0 errors (-p:IncludeNetFramework=true)
  • The new specs fail on the source of Give a nested error of a whole object the path of the object #87 (3 failures on net8.0), and pass with the fix. Commit order: specs, fix, docs.
  • CI on Windows runs the net481 tests

@tgharold
tgharold force-pushed the tgh-20261002-nested-class-level-error-path branch from f7f755e to 7d4e840 Compare October 2, 2026 20:56
Base automatically changed from tgh-20261002-nested-class-level-error-path to master October 2, 2026 20:59
tgharold and others added 3 commits October 2, 2026 17:00
A static property holds data of the type, not of the model, and
Validator, MVC and System.Text.Json ignore it. The walk read it because
Type.GetProperties() with no arguments returns static properties too,
so a shared invalid static object failed every model of that type.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Both the walk and the leaf type check now ask for public instance
properties. A static property is no longer walked, so a shared invalid
static object no longer fails every model of its type, and a static
property that builds a new object on each read no longer needs the
Equals check to stop.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tgharold
tgharold force-pushed the tgh-20261002-instance-properties-only branch from 26da9ea to be883a3 Compare October 2, 2026 21:00
@tgharold
tgharold merged commit 084b374 into master Oct 2, 2026
3 checks passed
@tgharold
tgharold deleted the tgh-20261002-instance-properties-only branch October 2, 2026 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant