I built a tool for users to import CSVs and create custom column mappings for the import. It uses the ChoETL csv tool to parse the CSV. I’m adding some boolean columns and I’m not sure how to validate the data to make sure that the values provided fit the ChoETL default setting, ChoBooleanFormatSpec.ZeroOrOne
.
Ideally, I would want to simply throw an exception (to be returned as a nice message) if the type isn’t correct. But when I tried putting “True” instead of a 1, ChoETL parsed it as false. How can I do this?
According to the documentation you can only choose one supported format.
Cinchoo ETL implicitly handles parsing/writing of boolean CSV column values from CSV files. If you want to fine control the parsing of these values, you can specify them globally via ChoTypeConverterFormatSpec.BooleanFormat. Default value is ChoBooleanFormatSpec.ZeroOrOne.
https://www.codeproject.com/Articles/1155891/Cinchoo-ETL-CSV-Writer#20.4%C2%A0BooleanSupport41
3
It is an issue with bool converter, defaulting to false
for incorrect values. applied fix. released nuget package v1.2.1.67
string csv = @"Id, Name, IsActive
1, Tom, 0
2, Mark, 1
3, Shelly, true";
using (var r = ChoCSVReader<EmployeeC>.LoadText(csv)
.WithFirstLineHeader()
.TypeConverterFormatSpec(ts => ts.BooleanFormat = ChoBooleanFormatSpec.ZeroOrOne)
)
{
r.Print();
}
Sample fiddle: https://dotnetfiddle.net/BR4a55
1