Standardize argument-name validation in OutputBuilderFactory#714
Merged
tannergooding merged 1 commit intoJul 13, 2026
Merged
Conversation
The five public methods each duplicated the same `string name` guard, split across two styles: an `if (string.IsNullOrWhiteSpace(name)) throw` block in `Create`/`CreateTests` and a ternary-throw form in `GetOutputBuilder`/`GetTestOutputBuilder`/`TryGetOutputBuilder`. Factor the check into a single private `ValidateName` helper and call it from every method so the guard lives in one place. Preserve exception semantics exactly. The existing guard throws `ArgumentNullException(nameof(name))` for null, empty, and whitespace names, so `ValidateName` retains the `string.IsNullOrWhiteSpace` check rather than switching to `ArgumentNullException.ThrowIfNull` (which would not throw for non-null empty/whitespace) or `ArgumentException.ThrowIfNullOrWhiteSpace` (which would throw `ArgumentException` instead). The distinct `ArgumentException` for a non-test builder in `GetTestOutputBuilder` is left unchanged. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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.
The five public methods on
OutputBuilderFactoryeach duplicated the samestring nameguard, split across two styles: anif (string.IsNullOrWhiteSpace(name)) throwblock inCreate/CreateTests, and a ternary-throw form inGetOutputBuilder/GetTestOutputBuilder/TryGetOutputBuilder. This factors the check into a single privateValidateNamehelper called from every method.ValidateNameis annotated[NotNull]on itsnameparameter so the analyzer treatsnameas non-null once it returns, matching howArgumentNullException.ThrowIfNullis annotated.Exception semantics are preserved exactly. The existing guard throws
ArgumentNullException(nameof(name))for null, empty, and whitespace names, soValidateNamekeeps thestring.IsNullOrWhiteSpacecheck rather than switching toArgumentNullException.ThrowIfNull(which would not throw for a non-null empty/whitespace name) orArgumentException.ThrowIfNullOrWhiteSpace(which would throwArgumentExceptioninstead ofArgumentNullException). The distinctArgumentExceptionfor a non-test builder inGetTestOutputBuilderis left unchanged.Build (Release): 0 warnings, 0 errors. Golden
PInvokeGenerator.UnitTests: 3708 passed, 0 failed.