Repository navigation
Use IValidatableTypeInfo.TryFindProperty instead of ValidationOptions.TryGetValidatablePropertyInfo - #67333
Merged
Conversation
….TryGetValidatablePropertyInfo
Youssef1313
commented
Jun 20, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR removes the redundant (unshipped) ValidationOptions.TryGetValidatablePropertyInfo API and updates callers to use the already-available per-property lookup on IValidatableTypeInfo via TryFindProperty, keeping the validation metadata surface area smaller and less duplicative.
Changes:
- Removed
ValidationOptions.TryGetValidatablePropertyInfoand its unshipped public API entry. - Updated Blazor Forms per-field validation to resolve the type info and then call
IValidatableTypeInfo.TryFindProperty. - Updated validation tests to assert against
TryFindPropertyinstead of the removedValidationOptionsmethod.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| src/Validation/test/Microsoft.Extensions.Validation.Tests/ValidatableTypeInfoTests.cs | Updated tests to use TryFindProperty (with minor test-name nits noted in comments). |
| src/Validation/src/ValidationOptions.cs | Removed the redundant TryGetValidatablePropertyInfo API. |
| src/Validation/src/PublicAPI.Unshipped.txt | Removed the unshipped API declaration for TryGetValidatablePropertyInfo. |
| src/Components/Forms/src/EditContextDataAnnotationsExtensions.cs | Updated per-field validation path to use TryGetValidatableTypeInfo + TryFindProperty. |
Comment on lines
+673
to
+675
| var retrievedNameProperty = typeInfo.TryFindProperty("Name", options); | ||
| Assert.NotNull(retrievedNameProperty); | ||
| Assert.Same(nameProperty, retrievedNameProperty); |
Comment on lines
+694
to
+699
| var localProperty = derivedType.TryFindProperty("Name", options); | ||
| Assert.NotNull(localProperty); | ||
| Assert.Same(nameProperty, localProperty); | ||
|
|
||
| Assert.True(options.TryGetValidatablePropertyInfo(typeof(DerivedEntity), "Id", out var inheritedProperty)); | ||
| var inheritedProperty = derivedType.TryFindProperty("Id", options); | ||
| Assert.NotNull(inheritedProperty); |
Comment on lines
722
to
724
| var propertyInfo = derivedType.TryFindProperty("Name", options); | ||
| Assert.NotNull(propertyInfo); | ||
| Assert.Same(derivedNameProperty, propertyInfo); |
Comment on lines
740
to
745
| var localProperty = derivedType.TryFindProperty("Name", options); | ||
| Assert.NotNull(localProperty); | ||
| Assert.Same(nameProperty, localProperty); | ||
|
|
||
| Assert.False(options.TryGetValidatablePropertyInfo(typeof(DerivedEntity), "Id", out var inheritedProperty)); | ||
| var inheritedProperty = derivedType.TryFindProperty("Id", options); | ||
| Assert.Null(inheritedProperty); |
Comment on lines
+764
to
+767
| Assert.True(options.TryGetValidatableTypeInfo(typeof(DerivedEntity), out var derivedEntityInfo)); | ||
|
|
||
| var fromDerived = derivedEntityInfo.TryFindProperty("Name", options); | ||
| Assert.NotNull(fromDerived); |
Comment on lines
795
to
797
| var resolved = thingTypeInfo.TryFindProperty("CreatedAt", options); | ||
| Assert.NotNull(resolved); | ||
| Assert.Same(auditedProperty, resolved); |
Youssef1313
marked this pull request as draft
June 21, 2026 04:08
Youssef1313
marked this pull request as ready for review
June 24, 2026 11:53
oroztocil
approved these changes
Jun 24, 2026
oroztocil
left a comment
Member
There was a problem hiding this comment.
Please update the tests, otherwise it is good 👍
oroztocil
approved these changes
Jun 25, 2026
Co-authored-by: Youssef Fahmy <[email protected]>
Member
Author
|
/ba-g unrelated quarantine pipeline timeout. |
Youssef1313
enabled auto-merge (squash)
June 25, 2026 17:28
Open
3 tasks
oroztocil
approved these changes
Jun 26, 2026
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.
This mostly goes the opposite way of #66955 and removes that public API.
When we split the interfaces, we already have a way to get properties from
IValidatableTypeInfo. TheTryGetValidatablePropertyInfoimplementation simply just calls into the public API ofIValidatableTypeInfoand so it's redundant to have both as public APIs.The PR also switches the TryFindProperty to be bool-returning with out parameter. This is a change over the originally approved API which was discussed internally via email.
@oroztocil Let me know what you think, and we can take this to API review, assuming it's required for no-longer shipped APIs that were previously approved.