CanleyCSVReader

Namespace: Canley.Utility.CSV
Base Class: System.Object

Overview

The CanleyCSVReader is a high-performance, memory-efficient engine responsible for navigating and extracting data from a parsed CSV structure. Unlike the Manager, the Reader is purely focused on data retrieval and provides safe, index-based access to rows and columns.

It supports both header-based lookups (for readability) and index-based lookups (for performance-critical loops).


Method Reference

Detailed documentation for each method can be found in the CanleyCSVReader subfolder.

ClassMethod (Syntax)Description
CanleyCSVReadervoid Load(string rawData)The core engine. Parses a raw string into the internal data grid.
CanleyCSVReadervoid Clear()Manually wipes the internal data grid, resetting the Reader to an empty state.
CanleyCSVReaderstring GetCell(int row, int col)Retrieves a specific cell value. Returns string.Empty if out of bounds.
CanleyCSVReaderint GetHeaderIndex(string name)Finds the column index by header name. Returns -1 if not found.
CanleyCSVReaderint GetRowCount()Returns the total number of rows currently loaded in the Reader.
CanleyCSVReaderint GetColumnCount(int row)Returns the number of columns found in a specific row.
CanleyCSVReaderbool Validate(out string report)Checks for column count consistency. Outputs a detailed error report.
CanleyCSVReaderList<string[]> GetRawGrid()Returns the internal List<string[]> structure.

Key Features

  • Zero-Allocation Ready: Optimized to minimize garbage collection spikes when accessing large datasets in real-time.
  • Flexible Lookups: Automatically maps header strings to column indices, allowing you to reorder your CSV columns without breaking your C# code.
  • Error Resilience: Includes “Safe-Get” logic to prevent IndexOutOfRangeException when dealing with malformed or inconsistent CSV rows.

TIP

For the best performance in Update() loops or large data processing, cache your Column Indices once and use them for integer-based lookups instead of string-based lookups.

8 items under this folder.