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.
| Class | Method (Syntax) | Description |
|---|---|---|
| CanleyCSVReader | void Load(string rawData) | The core engine. Parses a raw string into the internal data grid. |
| CanleyCSVReader | void Clear() | Manually wipes the internal data grid, resetting the Reader to an empty state. |
| CanleyCSVReader | string GetCell(int row, int col) | Retrieves a specific cell value. Returns string.Empty if out of bounds. |
| CanleyCSVReader | int GetHeaderIndex(string name) | Finds the column index by header name. Returns -1 if not found. |
| CanleyCSVReader | int GetRowCount() | Returns the total number of rows currently loaded in the Reader. |
| CanleyCSVReader | int GetColumnCount(int row) | Returns the number of columns found in a specific row. |
| CanleyCSVReader | bool Validate(out string report) | Checks for column count consistency. Outputs a detailed error report. |
| CanleyCSVReader | List<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
IndexOutOfRangeExceptionwhen 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.