Search code examples
c#nuget-packagecsvhelper

Upgrading from CsvHelper, fix breaking changes


As shown on the GitHub of CsvHelper project the config is read only now so I've moved the property initialization into the constructor. There is also a property which is now unsupported: IgnoreQuotes.

What's the new corrisponding parameter?

var config = new CsvConfiguration(CultureInfo.InvariantCulture)
                {
                    HasHeaderRecord = true,
                    BadDataFound = null,
                    Delimiter = ",",
                    Quote = '"',
                    
                    IgnoreQuotes = true

            };

Solution

  • Instead of IgnoreQuotes there are ParserModes. As of version 21.1.0 there are 3 modes.

    • RFC4180
    • Escape
    • NoEscape

    RFC4180 will treat fields like the "spec" says and expect double quotes around fields that contain a delimiter, newline or double quote. If a field has a double quote in it, it needs to be escaped (preceded) by a double quote.

    Escape will use an escape character only and ignore the character immediately after the escape.

    NoEscape will ignore double quotes and escape characters. This means a field can't contain a delimiter, double quote, or newline, as there is no way to escape them.

    You can set the delimiter (string), quote (char), escape (char), and newline (string).