"N/A" as null value of int field

You can define a custom type converter like this:

using CsvHelper;
using CsvHelper.TypeConversion;
using CsvHelper.Configuration;

public class CustomInt32Converter: Int32Converter {
    public override object ConvertFromString(string text, IReaderRow row, MemberMapData memberMapData)
    {
        if (text == "N/A") return 0;
        return base.ConvertFromString(text, row, memberMapData);
    }
}

Then you can register your converter with this line:

csv.Configuration.TypeConverterCache.AddConverter<int>(new CustomInt32Converter());

Tags:

C#

Csvhelper