Search code examples
c#csvfilehelpers

FieldQuotes on all properties


Is there an attribute like FieldQuotes that I can apply to properties?

Also, is it possible to add FieldQuotes to all fields automatically so that I don't have to define it for each and every field?


Solution

  • The attribute you are looking for is FieldQuoted. The documentation is here.

    Some examples:

    [FieldQuoted()] // Quoted with "
    public string CustomerName
    
    [FieldQuoted('[')] // Quoted between [brackets]
    public string CustomerName
    
    [FieldQuoted('"', QuoteMode.OptionalForBoth)] // Optional quoted when read or write
    public string CustomerName
    
    [FieldQuoted('"', MultilineMode.AllowForBoth)] // Indicates that the quoted string can span multiple lines
    public string CustomerName
    

    You do need to apply to every field.