The idea is simple. Take a CSV file, sprinkle some dynamic and ExpandoObject magic, and get a list of plain old object back.
Warning - this is a toy and experimental code. Perhaps it will turn into something, perhaps it will not. Who knows.
First, add a reference to DynoPhile.dll
For a file with a header: make the call:
var magic = new DynoPhile().ReadFile(fileName, ",");
for a file without a header, you can supply your own function to build out the dynamic properties:
public class DoMagic()
{
var magic = new DynoPhile().ReadFile(fileName, "|", BuildProperties);
}
private static dynamic BuildProperties()
{
dynamic header = new ExpandoObject();
header.FirstName = string.Empty;
header.LastName = string.Empty;
header.TwitterHandle = string.Empty;
return header;
}
so given an example CSV file:
"FirstName","LastName","Twitter" "Jeff","Schumacher","codereflection" "Bobby","Johnson","notmyself" "Eric","Ridgeway","ang3lfir3"
DynoPhile will give you dynamic awesome in return:
foreach (var item in magic)
{
Console.WriteLine("{0} {1}, @{2}", item.FirstName, item.LastName, item.Twitter);
}