Upgraded to latest version and this broke.
ShouldQuote replaces QuoteAllFields, QuoteNoFields, QuoteRequiredChars, and BuildREquiredQuoteChars.
You can do this now.
csv.Configuration.ShouldQuote = (field, context) => true;
This is the default implementation. https://github.com/JoshClose/CsvHelper/blob/7f6896ff4775e5962c3462bf5606104926148a36/src/CsvHelper/Configuration/ConfigurationFunctions.cs#L86
I need to update the change log.
Thanks that worked!
The change log has been updated.
Not sure if you're aware, but the documentation still says to use QuoteAllFields, QuoteNoFields, etc
Yes, only the change log was updated.
I'm actually working on a new layout for the documentation that will make it more easy to navigate. It'll be the api, then a bunch of examples on how to do things. Should make things easier.
This broke my project. Suggestion, keep it in and in the implementation hook up to the code you mention (thus abstracting it away from users who don't need granular control).
The more powerful functionality is nice, but I think it makes it more complex and less intuitive than many users need?! You have the added bonus of not breaking existing code.
The problem is they conflict with each other. Also, if you set ShouldQuote, should it ignore the other settings then? Having both makes things really complicated. It also had some hidden behavior before. If you set QuoteAllFields = true it would set QuoteNoFields = false without you knowing, since they are in conflict with each other. There was a not in the xml comment, but it's still unexpected behavior.
There was a major version bump, which means breaking code, and I try to document all breaking changes in the change log. If you see that a new version is a major version change, check out the change log before you update and see if it will potentially break your code.
The new documentation will be mostly just lots of full examples on doing things. I think I may push it out sooner than later, and just work on adding more as I go. Basically any time there is a question, if I can't point to an example in the docs, then I'll add something.
I take your points, I just think for less advanced users or people with simple requirements (most users?), this might be overkill / hard to understand vs just having a property (not necessarily QuoteAllFields but something that achieves a similar goal).
I'll put an example in the docs, but it just changes from an assignment of a boolean to an assignment of a function that returns a boolean.
What if i only want to quote some fields and leave the others unquoted?
Configuration.ShouldQuote
Hi Josh, thank you for replying. I have already written this
csvWriter.Configuration.ShouldQuote = (field, context) => context.HasHeaderBeenWritten == false;
What i am tying to do is
csvWriter.Configuration.ShouldQuote = (field, context) => ListOfInt.Contains(field.Index);
So only some fields that i have selected are quoted.
@JoshClose - thanks for your work on this project. We, unfortunately, have to deal with XML in our CSV and using the ShouldQuote really helped out
Most helpful comment
ShouldQuotereplacesQuoteAllFields,QuoteNoFields,QuoteRequiredChars, andBuildREquiredQuoteChars.You can do this now.
This is the default implementation. https://github.com/JoshClose/CsvHelper/blob/7f6896ff4775e5962c3462bf5606104926148a36/src/CsvHelper/Configuration/ConfigurationFunctions.cs#L86
I need to update the change log.