This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is a .NET CSV parsing and writing library (Csv) that supports multiple target frameworks (netstandard2.0, net8.0, net9.0). The library provides simple and efficient CSV reading and writing capabilities with extensive configuration options.
CsvReader(Csv/CsvReader.cs) - Main static class for reading CSV data from various sources (TextReader, Stream, string, ReadOnlyMemory)- Contains multiple implementations: standard
Read*,ReadAsSpan*(NET8.0+), andReadAsync*methods - Inner classes:
ReadLine(standard),ReadLineSpan(NET8.0+),ReadLineSpanOptimized(memory-optimized)
- Contains multiple implementations: standard
CsvReader.FromMemory.cs- Partial class containing memory-optimized reading methodsCsvWriter(Csv/CsvWriter.cs) - Static class for writing CSV data to various outputsCsvOptions(Csv/CsvOptions.cs) - Configuration class containing parsing options (separators, headers, validation, etc.)CsvMemoryOptions(Csv/CsvMemoryOptions.cs) - Memory management options for optimized parsing (NET8.0+)ICsvLine(Csv/ICsvLine.cs) - Interface for accessing CSV row data by index or column name (string-based)ICsvLineSpan(Csv/ICsvLineSpan.cs) - Interface extending ICsvLine with Span/Memory support (NET8.0+)ICsvLineFromMemory(Csv/ICsvLineFromMemory.cs) - Legacy memory-based interfaceCsvLineSplitter(Csv/CsvLineSplitter.cs) - Low-level CSV line parsing logic- Key method:
IsUnterminatedQuotedValue- detects multiline field continuation
- Key method:
CsvBufferWriter(Csv/CsvBufferWriter.cs) - Buffer-based CSV writer for optimized writing (NET8.0+)StringHelpers(Csv/StringHelpers.cs) - String manipulation utilities including unescape operationsHeaderMode(Csv/HeaderMode.cs) - Enum defining header handling modes (HeaderPresent, HeaderAbsent)
Csv/- Main library project containing all CSV functionalityCsv.Tests/- MSTest-based unit tests for the librarydocs/- Documentation including PRDs (Product Requirement Documents) and implementation guides- Solution - Standard .NET solution with library + tests projects
- Multi-framework targeting (netstandard2.0, net8.0, net9.0)
- Async support (
IAsyncEnumerablefor NET8.0+) - Memory-efficient parsing with
ReadOnlyMemory<char>andReadOnlySpan<char>support (NET8.0+) - Extensive configuration options through
CsvOptions - Header-aware parsing with column name access
- Quote handling and escape sequences
- Custom separators with auto-detection
- Multiline field support via
AllowNewLineInEnclosedFieldValues - AOT and trimming compatible (NET8.0+)
Important: The codebase uses #if NET8_0_OR_GREATER directives extensively. Modern Span/Memory APIs are only available for NET8.0+, while netstandard2.0 uses string-based equivalents with type aliases (MemoryText and SpanText).
dotnet builddotnet testdotnet test --filter "TestMethodName"dotnet packdotnet build -f net8.0The project uses MSTest framework with test files in Csv.Tests/:
Tests.cs- Main CSV parsing testsWriterTests.cs- CSV writer testsIssuesTests.cs- Regression tests for reported issuesMemoryTests.cs- Memory-specific parsing testsSpanMemoryTests.cs- Span/Memory API tests (NET8.0+)RegexEliminationTests.cs- Tests for regex-free parsingPerformanceTests.cs/RegexPerformanceTests.cs- Performance benchmarks
The tests target net9.0. When adding tests for framework-specific features (NET8.0+ Span/Memory APIs), use appropriate #if NET8_0_OR_GREATER directives.
CSV parsing behavior is controlled through CsvOptions which includes:
- Separator detection/specification
- Header handling modes (HeaderPresent, HeaderAbsent)
- Quote and escape handling (
AllowEnclosedFieldValues,AllowBackSlashToEscapeQuote,AllowSingleQuoteToEncloseFieldValues) - Row skipping and validation (
RowsToSkip,SkipRow,ValidateColumnCount) - Multiline field support (
AllowNewLineInEnclosedFieldValues) - Column aliases and case-insensitive matching
- Memory vs string parsing (standard vs Span/Memory APIs)
The library supports CSV fields that span multiple lines when enclosed in quotes. The logic works by:
CsvLineSplitter.IsUnterminatedQuotedValue()checks if a field's quotes are unbalanced- When detected,
CsvReadercontinues reading lines and concatenates them - Special handling exists for
HeaderAbsentmode to avoid re-processing the first data line
- HeaderPresent (default): First non-skipped row is treated as headers; duplicate headers cause an error
- HeaderAbsent: Auto-generates column names as "Column1", "Column2", etc.
- Aliases can be configured to provide alternative names for the same column
- NET8.0+ builds use
ReadOnlySpan<char>andReadOnlyMemory<char>to minimize allocations CsvMemoryOptionsprovides ArrayPool-based buffering for high-performance scenarios- Type aliases (
MemoryText/SpanText) allow code sharing between netstandard2.0 and NET8.0+ - AOT and trimming attributes are set for NET8.0+ builds
- All PRDs should be placed in the
docs/folder - Use descriptive names like
Feature-Name-PRD.md - Include implementation documents alongside PRDs when available
- Examples:
Span-Memory-PRD.md,Regex-Elimination-Enhancement-PRD.md