Skip to content

Use IValidatableTypeInfo.TryFindProperty instead of ValidationOptions.TryGetValidatablePropertyInfo - #67333

Merged
Youssef1313 merged 6 commits into
mainfrom
dev/ygerges/split-followup
Jun 26, 2026
Merged

Youssef1313 merged 6 commits into
mainfrom
dev/ygerges/split-followup

Conversation

@Youssef1313

@Youssef1313 Youssef1313 commented Jun 20, 2026 •

Copy link
Copy Markdown
Member

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. The TryGetValidatablePropertyInfo implementation simply just calls into the public API of IValidatableTypeInfo and 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.

Copilot AI review requested due to automatic review settings June 20, 2026 21:32
@Youssef1313
Youssef1313 requested a review from a team as a code owner June 20, 2026 21:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.TryGetValidatablePropertyInfo and 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 TryFindProperty instead of the removed ValidationOptions method.

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
Youssef1313 marked this pull request as draft June 21, 2026 04:08
@Youssef1313
Youssef1313 marked this pull request as ready for review June 24, 2026 11:53

@oroztocil oroztocil left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the tests, otherwise it is good 👍

@oroztocil oroztocil left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just two nits

@Youssef1313

Copy link
Copy Markdown
Member Author

/ba-g unrelated quarantine pipeline timeout.

@Youssef1313
Youssef1313 merged commit 73a4975 into main Jun 26, 2026
23 of 25 checks passed
@Youssef1313
Youssef1313 deleted the dev/ygerges/split-followup branch June 26, 2026 09:08
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jun 28, 2026
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.

3 participants