.NET how to output csv from enumeration of anonymous type?

Posted by Ronnie Overby on Stack Overflow See other posts from Stack Overflow or by Ronnie Overby
Published on 2010-06-08T21:06:21Z Indexed on 2010/06/09 2:32 UTC
Read the original article Hit count: 377

Filed under:
|
|
|
|

Using FileHelpers, I decorated a class with [DelimitedRecord(",")] and was going to output an enumeration of objects of that type as CSV. But, it didn't work because my class inherits from ActiveRecordLinqBase<T>, which caused some problems.

So, I was wondering if I could just select an enumeration of anonymous types and somehow have filehelpers generate csv from that. I don't like having to define a class just for FileHelpers to output csv.

I would be open to using another csv library, but FileHelpers is proven.

EDIT

@Foovanadil: This would be the sort of thing I am trying to do:

CreateCSV(MyCollection.Select(x=>new{
    x.Prop1,
    x.Prop2,
    x.Prop3
}));

Gives you:

Prop1,Prop2,Prop3
val1a,val2a,val3a,
val1b,val2b,val3b,
etc.....

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET