Detailed Method Reference

Namespace: Canley.Utility.CSV.Standard
Class: CSVRecord

Definition

public virtual bool OnImportField(string header, string value)
  • Description: A virtual callback method allowing derived record classes to intercept and handle custom column imports during record initialization.

  • Workflow:

    1. Interception: Called during the parsing loop for each column header and value pair.
    2. Custom Mapping: Derived classes can override this method to parse custom properties manually, returning true if the field was handled or false to let the default system take over.
  • Parameters:

    • header: The name of the CSV column header currently being processed.
    • value: The raw string value corresponding to the current column.
  • Returns: bool - true if the field was successfully handled by the override; otherwise, false.

  • Example:

public class CustomCSVRecord : CSVRecord
{
    public int customScore;
 
    public override bool OnImportField(string header, string value)
    {
        if (header == "CustomScore")
        {
            int.TryParse(value, out customScore);
            return true;
        }
        
        return base.OnImportField(header, value);
    }
}

TIP

Override OnImportField when you need specialized parsing logic for non-standard columns without having to rewrite the core hydration loop.