Skip to content

Add convention-based customization to the Sep source generator - #589

Draft
nietras with Copilot wants to merge 6 commits into
sourcegeneratorfrom
copilot/brainstorm-csv-source-generator
Draft

nietras with Copilot wants to merge 6 commits into
sourcegeneratorfrom
copilot/brainstorm-csv-source-generator

Conversation

Copilot AI commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

The source generator previously required attribute-configured converters for custom parsing and formatting. This adds compile-time conventions that emit direct, allocation-free calls while retaining converter compatibility.

Changes

  • Member conventions

    • Discover Parse{Member}, TryParse{Member}, and Format{Member} on partial adapters.
    • Support SepReader.Col/SepWriter.Col and row-level hooks for computed or multi-column values.
    • Preserve nullable types and generated optional-column handling.
  • Type-wide conventions

    • Apply Parse, TryParse, and Format overloads to members with matching declared types.
    • Resolve row before column hooks and member-specific before type-wide hooks.
  • Diagnostics

    • Report invalid or ambiguous signatures, incomplete parse pairs, and converter conflicts.
    • Make TryParse-only hooks throw an informative FormatException from generated Parse.
  • Compatibility

    • Retain SepCol.Converter as a deprecated fallback.
    • Document the convention model and migration path.
[SepSourceGeneration(typeof(Person))]
public static partial class PersonSepExtensions
{
    static StrongId ParseId(SepReader.Col col) => new(col.Parse<int>());

    static bool TryParseId(SepReader.Col col, out StrongId value)
    {
        var success = col.TryParse<int>(out var parsed);
        value = new(parsed);
        return success;
    }

    static void FormatId(SepWriter.Col col, StrongId value) =>
        col.Format(value.Value);
}

Copilot AI and others added 3 commits August 31, 2026 14:34
Co-authored-by: nietras <10798831+nietras@users.noreply.github.com>
Co-authored-by: nietras <10798831+nietras@users.noreply.github.com>
Co-authored-by: nietras <10798831+nietras@users.noreply.github.com>
@nietras

nietras commented Aug 31, 2026

Copy link
Copy Markdown
Owner

@copilot there needs to be convention based overriding of which column index or name is used based on header as parameter or null if none. think this through. and remove old converter based stuff.

Copilot AI and others added 2 commits August 31, 2026 17:28
Co-authored-by: nietras <10798831+nietras@users.noreply.github.com>
Co-authored-by: nietras <10798831+nietras@users.noreply.github.com>

Copilot AI commented Aug 31, 2026

Copy link
Copy Markdown
Contributor Author

@copilot there needs to be convention based overriding of which column index or name is used based on header as parameter or null if none. think this through. and remove old converter based stuff.

Implemented in ea00238 with follow-up validation in 9de3f22. GetColumn{Member}(SepReaderHeader?) can now select a read column by index or name (with null for headerless readers), and converter-based configuration has been removed.

Co-authored-by: nietras <10798831+nietras@users.noreply.github.com>

This branch has not been deployed

No deployments
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.

2 participants