I am trying to parse a csv file using csv helper
this is my maping class
sealed class CSVFileDefinitionMapFinal : CsvClassMap<CSVFileDefinitionFinal>
{
public CSVFileDefinitionMapFinal()
{
Map(m => m.FARM_ID).Name("FRM_ID");
}
}
this is my item class
class CSVFileDefinitionFinal
{
public int FARM_ID { get; set; }
}
the problem is that the FRM_ID
in the csv may hav null
. so when I do the mappign above, I have an exception that null can't be transfer to integer. I am asking about if there is a way to try and catch that and set the value to -10 when it is null.
the try and catch should be in the maping class, but I couldn't know what to do after catching the exception. in other words, i couldn't know how to set default value to the maping object