有没有为CSV串行这样的事情? (类似的XmlSerializer) [英] Is there such thing as a CSV Serializer? (similar to XmlSerializer)

查看:837
本文介绍了有没有为CSV串行这样的事情? (类似的XmlSerializer)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与序列化和反序列化的CSV文件玩弄周围,我想知道如果有一个现有的库,在概念上与XmlSerializer的,它可以声明定义对象和(德),他们从一个文件或流序列化/相似。我曾四处张望了一下,但没有发现任何东西集中在序列化。我已经有解析每RFC 4180 CSV文件非常稳固代码,但什么是真正有用的是序列化的一部分。我是什么的的寻找只是一个解析器,建议使用String.Split()等。

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 declaratively define objects and (de)serialize them to/from a file or stream. I have looked around a bit but have not found anything focused on serialization. I already have pretty solid code for parsing CSV documents per RFC 4180, but what would be really helpful is the serialization part. What I am not looking for is just a parser, advice to use String.Split(), etc.

是否有一个?现有的项目在那里,或者我应该建有一个

奖金礼仪问题:如果我结束了我自己的滚动序列化,它是适合回答这个一个链接到CodePlex项目的问题?

Bonus etiquette question: if I do end up rolling my own serializer, is it appropriate to answer this question with a link to the codeplex project?

推荐答案

我会极力推荐的servicestack.text 的用于这一目的。可用的编缉上的NuGet:

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

Install-package servicestack.text

据suports系列化很多数据格式和不同的是建于XmlSerializer的,你并不需要的属性来装饰您的所有属性。这里是序列化到CSV为例

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
}});

这篇关于有没有为CSV串行这样的事情? (类似的XmlSerializer)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆