Skip to content

Keep items whose ToString() is null in ToStringEnumerable and Join [patch] - #163

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/153-null-tostring
Oct 9, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/153-null-tostring

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #153

What changes

This follows the triage on the issue. NullItemHandling now tests the item, as the XML docs say ("null items"), and never tests the string the item turns into.

  • ToStringEnumerable(items, h) filters on the item, then projects it. A non-null item whose ToString() returns null becomes "" in every mode, so Throw no longer silently removes an element.
  • Join(items, sep, h) is now string.Join(sep, items.ToStringEnumerable(h)). The invariant Join(sep, h) == string.Join(sep, ToStringEnumerable(h)) therefore holds by construction.
  • The <returns> doc now states this rule.

For the issue's repro [new N(), "x"], ToStringEnumerable now gives ["", "x"] in all three modes, matching Join's ",x". The parameterless ToStringEnumerable() also keeps such an item as "" where it used to drop it. #138's single-pass enumeration is unchanged.

Tests

  • New tests cover every NullItemHandling mode, the parameterless overload, and Join/ToStringEnumerable agreement.
  • With the fix reverted, 5 of the new test cases fail. With the fix, the full suite passes (182 tests). The Release build passes on every target framework.

🤖 Generated with Claude Code

https://claude.ai/code/session_01P2fpLkFHYU6nd3JVKufVtK


Generated by Claude Code

… Join

ToStringEnumerable filtered on the projected string, so NullItemHandling.Throw
and Remove silently dropped a non-null item whose ToString() returns null,
while Join emitted the same item as an empty entry. Null handling now tests
the item only, such an item becomes "", and Join delegates to
ToStringEnumerable so the two always agree.

Fixes #153

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01P2fpLkFHYU6nd3JVKufVtK
@sonarqubecloud

sonarqubecloud Bot commented Oct 9, 2026

Copy link
Copy Markdown

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.

ToStringEnumerable(NullItemHandling.Throw) silently drops items whose ToString() returns null, and Join keeps the same items as empty entries

2 participants