Clarify ObjectInstance behavior when no owning object is available - #131900
Conversation
…parameter/standalone validation
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
Pull request overview
This PR updates the XML doc remarks for ValidationContext.ObjectInstance to clarify expectations about the object instance available during validation, especially in scenarios where an “owning” object may not exist.
Changes:
- Adds a new remark explaining
ObjectInstanceis not meaningful in some ownerless/standalone validation scenarios.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (1)
src/libraries/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/ValidationContext.cs:152
- The new remarks call out that
ObjectInstance"may be a placeholder", butObjectInstanceis always whatever was supplied to theValidationContextconstructor. Saying it's a placeholder can read like framework-provided behavior (or that it has no value at all), and it also conflicts a bit with the summary stating this is the object instance being validated. Consider wording this in terms of the constructor-provided instance not necessarily being an owning object when validating standalone values.
/// When validation is performed without an owning object (for example, validating standalone values),
/// <see cref="ObjectInstance" /> may be a placeholder and should not be treated as the owner of the value.
Co-authored-by: Jeff Handley <jeffhandley@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (1)
src/libraries/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/ValidationContext.cs:156
- The new remarks say
ObjectInstance"may be a placeholder" for standalone validation, but the placeholder comes from whatever the caller passes intoValidationContext(the framework doesn’t supply one). Calling this out explicitly (and pointing toValidator.TryValidateValue) would make the guidance more accurate/actionable for attribute authors.
/// <para>
/// When validation is performed without an owning object (for example, validating standalone values),
/// <see cref="ObjectInstance" /> may be a placeholder and should not be treated as the owner of the value.
/// </para>
|
/ba-g Helix timeout (7 jobs show as unfinished or unprocessed) and known flake #125825 only |
Updated the doc comment to make it clear that ObjectInstance has no meaningful value when validation is performed outside the context of an owning object, helping avoid incorrect assumptions by attribute authors.