Is there such thing as a CSV Serializer? (similar to XmlSerializer)

前端 未结 3 878
-上瘾入骨i
-上瘾入骨i 2021-01-17 10:18

I am toying around with serializing and deserializing CSV files and I am wondering if there is an existing library, similar in concept to the XmlSerializer, which can declar

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-17 11:00

    I would highly recommend servicestack.text for this purpose. Avialable on nuget:

    Install-package servicestack.text
    

    It suports serialization to many data formats and unlike the built in XmlSerializer, you don't need to decorate all your properties with attributes. Here's an example to serialize to CSV.

    using ServiceStack.Text;
    ...
    
    var csv = CsvSerializer.SerializeToCsv(new[]{
        new Dog () {
        Bark = "Woof!",
        Male = true,
        Size = 10
    }});
    

提交回复
热议问题