Skip to content

Refactor CommandArg.TryGet type dispatch into a table-driven registry #59

Description

@wallstop

DISCLOSURE: LLM-GENERATED TEXT

Follow-up from PR #57 review (CommandArg.cs:209): CommandArg.TryGet<T> is one giant
method — a ~400-line if (type == typeof(X)) chain with inline switch cases per
composite type, plus local helper functions. It works (192/192) but is hard to navigate,
and every new type widens the chain.

Proposed shape

  • Table-driven dispatch: a static Type -> parser delegate map built once and consulted
    by TryGet (the RegisteredParsers/StaticProperties/ConstFields/EnumValues
    caches already establish the pattern).
  • Composite-type parsing (Vector2/3/4, Vector2Int/3Int, Color, Quaternion, Rect,
    RectInt) moves to per-type parse functions beside the new public
    CommandArgParsers class, so delimiter/quote handling stays in one place.
  • Keep public behavior exactly: same accepted formats, same TryGet semantics, same
    precedence (per-call parser override -> registered parser -> built-in -> enum ->
    named constants). The culture-invariance work in Warnings as errors + built-in analyzers (#55), user-facing changelog (#54) #57 (NumberStyles + InvariantCulture
    pinned per type) must survive unchanged, along with the ParsingIsCultureInvariant
    PlayMode cases.
  • No public API change: TryGet, TryGet<T>(parser), RegisterParser,
    CommandArgParser<T> keep their signatures.

Acceptance

  • Existing PlayMode suites pass unchanged (TryEatArgument parity,
    ParsingIsCultureInvariant, custom-parser cases).
  • Adding a built-in type = one table entry + one parser function, not another
    else if arm (pairs with the built-in-types issue).
  • No allocation regressions on the TryGet hot path (parse calls stay direct delegates;
    no boxing in the common path).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions