Skip to content

DbQuery and command checks share their code - #238

Merged
electricessence merged 5 commits into
masterfrom
refactor/area-d-reduction
Nov 24, 2026
Merged

electricessence merged 5 commits into
masterfrom
refactor/area-d-reduction

Conversation

@electricessence

Copy link
Copy Markdown
Collaborator

Behavior-preserving code reduction: shared code where the same check or the same call was written twice. No caller-visible change.

  • DbQueryUsing: the three state-based reader members forward to ToCall().Run/RunAsync (the struct's own methods, no interface, no boxing), and the four places that built the same call by hand use ToCall(). An unbound value still throws InvalidOperationException from each member, before anything runs.
  • The equality and hash of a bound query and of a call share one helper; the hash values are unchanged.
  • The blank-text check of a DbQuery and of a parameter name share one helper that takes the message, so both messages, the argument names and the null-before-blank order are as they were. The throw is built out of line so the check stays small on the AddParam path.
  • The command constructors share one command check, still called after the transaction is set.

Left alone on purpose: the sync/async twins (their bodies differ in what they await), the two AddParams hooks of the plain and the DbCommand command (not shareable: the type of a parameter is the generic database type there), and the object and typed parameter loops.

Pinned by new tests: each message and argument name, null before blank, the sync throw of every state member of an unbound query, the equality of a bound query and a call, and their hash values.

Verification: full gate on the commit before the last test-only edit (Release and Debug tests on net11.0 and net10.0, 14,489 pass; benchmarks build; 214 sample checks; DocFX; VS MSBuild 0); after the last edit (a helper in the new test file) the new tests (17) and the Roslynator scan (0 on 10 projects) were rerun, not the whole gate. A Haiku swarm with a Sonnet arbiter reviewed it: no behavior or allocation difference found; its test fix is in. Not measured: a micro-benchmark of AddParam before and after (by reading, the check is smaller than before).

🤖 Generated with Claude Code

electricessence and others added 4 commits November 24, 2026 13:15
DbQueryUsing forwards its three state-based reader members to ToCall(), and uses ToCall() where it built the same call by hand. The equality and hash of a bound query and of a call share one helper, with the hash values unchanged. The blank-text checks of a DbQuery and of a parameter name share one helper that takes the message, so both messages and the null-before-blank order are as they were. The command constructors share one command check, called after the transaction is set as before.

The checks a caller sees are pinned by tests: each message and argument name, the null and blank order, the sync throw of every member of an unbound query, and the equality and hash of a bound query and a call.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… assertions

The shared text and command checks take a non-null string, as the code they replaced did, so the null checks are not flagged. The test file gets its using, awaits no value task it did not need, compares a message without the argument name the framework appends, and pins the hash of a call (the shared target hash times 31 plus the values' hash).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The CI format check flagged the object return type of the two helpers (CA1859); they now return nothing, so a throw from the call itself is what the test asserts.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@electricessence
electricessence marked this pull request as ready for review November 24, 2026 23:30
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@electricessence
electricessence merged commit d2c74dd into master Nov 24, 2026
10 checks passed
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