Search code examples
vb.netcsvhelper

using csvhelper writer with shouldquote in vb.net


I can see how shouldquote works with c# but does anyone have an example in vb.net?

I need to wrap every field with chr(34)


Solution

  • Private Sub Main()
        Dim records = New List(Of Foo) From {
            New Foo With {
                .Id = 1,
                .Name = "one"
            }
        }
        
        Dim config = New CsvConfiguration(CultureInfo.InvariantCulture) With {
            .ShouldQuote = Function(args) True 
        }
    
        Using csv = New CsvWriter(Console.Out, config)
            csv.WriteRecords(records)
        End Using
        
    End Sub
    
    Public Class Foo
        Public Property Id As Integer
        Public Property Name As String
    End Class