FileHelpers icon indicating copy to clipboard operation
FileHelpers copied to clipboard

Allow using a Type without any RecordAttribute

Open MarcosMeli opened this issue 10 years ago • 1 comments

Sometimes you can't edit an existing type to add the necessary attributes (DelimitedRecordAttribute or FixedLengthRecordAttribute) and this information could be specified through parameters. If the type doesn't have any attribute, you could use a default value, if this information is not specified through a parameter.

I've been annoyed when I wanted to proceed to a quick dump of data to a csv file without wanting to create a new object & copy data in order to be able to use the API.

I tried all possible engines and all of them seem to require those attributes. Even when it doesn't seem logical : CommonEngine.RecordsToDataTable() only works when the record type has those attributes. It's not logical because I don't think it need those attributes here.

It would also allow the use of anonymous types with the engines, like :

var itemList = data.GroupBy(item => new { item.NomApporteur }).Select(g => new { g.Key.NomApporteur, Somme = g.Sum(o => o.Montant) });
if (itemList.Count() > 0)
{
    var engine = new DelimitedFileEngine(itemList.First().GetType());
    engine.Options.Delimiter = ";";
    engine.WriteFile("", itemList);
}

Today, it seems that I have to write my own RecordsToDataTable() in order to bypass this limitation.

MarcosMeli avatar Jun 29 '15 01:06 MarcosMeli

This would be absolutely out standing! Do you know when this might have a chance to happen? I'm on deadline at the moment so I don't have time to do it myself, but I might have some time starting in January and would be happy to contribute back since I've used your library a couple times now.

barefootdeveloper avatar Oct 06 '15 03:10 barefootdeveloper