Detailed Method Reference

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

Definition

public virtual bool OnExportField(string header, ref string value)
  • Description: A virtual callback method allowing derived record classes to modify or provide custom string values when exporting data back out to CSV format.

  • Workflow:

    1. Interception: Called during the export loop for each column header before it gets written to the output stream.
    2. Custom Serialisation: Derived classes can override this method to inject custom-formatted property values into the export stream, returning true if the field was handled or false to use the default system values.
  • Parameters:

    • header: The name of the CSV column header currently being exported.
    • value: A reference to the raw string value that will be written out, allowing in-place modification.
  • Returns: bool - true if the field export was handled by the override; otherwise, false.

  • Example:

public class CustomCSVRecord : CSVRecord
{
    public DateTime lastModified;
 
    public override bool OnExportField(string header, ref string value)
    {
        if (header == "LastModified")
        {
            value = lastModified.ToString(provider: "yyyy-MM-dd");
            return true;
        }
        
        return base.OnExportField(header, ref value);
    }
}

TIP

Override OnExportField when you need to serialize complex types or custom fields back into standard string representations during CSV generation.