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:
- Interception: Called during the export loop for each column header before it gets written to the output stream.
- Custom Serialisation: Derived classes can override this method to inject custom-formatted property values into the export stream, returning
trueif the field was handled orfalseto 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-trueif 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
OnExportFieldwhen you need to serialize complex types or custom fields back into standard string representations during CSV generation.