Skip to content

feat: collection helpers return whether they changed the collection (v4.3.0) - #61

Merged
kamronbatman merged 1 commit into
mainfrom
feat/bool-collection-helpers
Oct 10, 2026
Merged

kamronbatman merged 1 commit into
mainfrom
feat/bool-collection-helpers

Conversation

@kamronbatman

@kamronbatman kamronbatman commented Oct 10, 2026 •

Copy link
Copy Markdown
Member

Problem

The generated collection helpers return void, so a caller that needs to know whether a removal happened cannot use them. It falls back to ISerializableExtensions.Remove(list, value), or a Contains check followed by RemoveFromX (two lookups). ModernUO's Corpse.OnItemLifted is an example: it removes the lifted item from EquipItems and branches on whether it was worn gear.

Changes

Return types now mirror the BCL. A helper that can be a no-op returns whether it changed anything:

Helper Before After
RemoveFromX (list, set, dictionary) void bool, like Remove
AddToX on a set void bool, like HashSet<T>.Add
AddToX on a dictionary void bool, like TryAdd
AddToX on a list, InsertIntoX, RemoveFromXAt, ReplaceInX, ClearX void unchanged
  • MarkDirty still fires only on an actual change, as in 4.2.0.
  • Without a dirty target (SG3019), the helpers return the mutation's result directly.
  • The ContainsKey + Add fallback for dictionaries without TryAdd returns bool too. No serializable type reaches that branch today, since only Dictionary<,> has a migration rule.
  • Generator, SchemaGenerator and Annotations bumped to 4.3.0. README install snippet updated, plus a line on the return values.

Compatibility

Callers that ignore the result keep compiling. A helper used as a method group for an Action<T> (e.g. list.ForEach(RemoveFromX)) would no longer compile. ModernUO has no such use.

Tests

  • DataStructureMethodTests.Helpers_TolerateNullAndMarkDirtyOnlyOnChange now asserts each helper's return value next to the dirty count: null collections, duplicates, missing entries, and successful adds and removes for lists, sets and dictionaries.
  • New Helpers_ReportChangesWithoutADirtyTarget runs the helpers on an entity with no dirty target.
  • 9 snapshot files changed, all in helper signatures and bodies. All 130 tests pass.

After merge

Run the Build and Publish NuGet Packages workflow. A ModernUO follow-up then bumps to 4.3.0 and replaces ISerializableExtensions.Remove call sites with the generated helpers, starting with Corpse.OnItemLifted.

…v4.3.0)

RemoveFromX, and AddToX on sets and dictionaries, now return bool, mirroring
the BCL's Remove, HashSet<T>.Add and TryAdd. Callers that branch on the
outcome no longer need ISerializableExtensions.Remove or a Contains check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kamronbatman
kamronbatman merged commit 569c4c0 into main Oct 10, 2026
2 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