Profiles and builders

A reader profile combines independent settings. Use a format-specific builder so its syntax defaults and supported options are applied before reading.

Part Responsibility Guide
Dialect/format Record boundaries, quoting, labels Format guides
Schema Field names, types, cultures and formats Schemas
Resource Encoding, compression, replacement sequences Input initialization, compression, nulls
Filters Conditions applied to exposed columns before materialization Reader filtering
Runtime parsers Conversion shared by runtime type Custom parsers
Parser options Buffering and supported format options Tuning
using System.Text;
using PocketCsvReader.Configuration;

var csv = new CsvReaderBuilder()
    .WithDialect(d => d.WithHeader().WithLineTerminator("\n"))
    .WithSchema(s => s.Named().WithField<int>("Id").WithField<string>("Name"))
    .WithResource(r => r.WithEncoding("utf-8"))
    .Build();
using var stream = new MemoryStream(Encoding.UTF8.GetBytes("Id,Name\n7,Ada\n"));
foreach (var row in csv.ToDictionaries(stream))
    Console.WriteLine($"{row["Id"]}: {row["Name"]}");
7: Ada

Builder overloads accept configuration callbacks and descriptors. CSV uses WithDialect; other builders expose their own format settings. Configure profiles before constructing/initializing a reader. Supplying a shared options record does not imply every format supports every option.

CSV column projection

Use WithProjection("CustomerId", "Country", "Amount") to select columns by exact header name and set their output order. Use zero-based source ordinals, such as WithProjection(3, 2, 0), for headerless files or when a source name occurs more than once.

The reader resolves the projection against each file’s effective header, including files that contain only headers. A batch configured with a shared header uses that header for each file. Missing or ambiguous names and ordinals outside the source width raise InvalidDataException.

Schema definitions and filters still refer to source columns. Output getters and metadata use projected ordinals. A generated row number remains at the front of the output, and projection ordinals count only CSV source columns.

JSON table builder

Use JsonTableReaderBuilder for arrays of row arrays. Choose WithHeaderRow() to read names from the first array, or WithoutHeaderRow(columnNames) to supply them. The default uses the first array as the header. JSON table examples

Generated row-number column

WithRowNumber() prepends an int column named rowNumber; WithRowNumber("recordId") selects another name, and WithoutRowNumber() disables it. Direct profiles use RowNumber = new RowNumberOptions() or null. See batch reading and row numbering for numbering, headers, collisions, and object mapping.

Class CsvReaderBuilder

The current method is WithDialect(...), followed by Build(). Dialect methods and defaults are documented in CSV and TSV.

Class DialectDescriptorBuilder

Use this builder to produce a DialectDescriptor, or pass its callback directly to WithDialect. See the dialect reference and configuration validation.


Use inverted indexes
Schemas, formats, and cultures