Skip to content

Instantly share code, notes, and snippets.

@msbukkuri
Created September 30, 2011 04:50
Show Gist options
  • Save msbukkuri/1252697 to your computer and use it in GitHub Desktop.
Save msbukkuri/1252697 to your computer and use it in GitHub Desktop.
CsvPrinter
public class CsvPrinter : ICsvPrinter
{
public void PrintCsv(IEnumerable<PropertyInfo> propertyInfos, IEnumerable<object> instances)
{
var output = new StringBuilder();
var properties = propertyInfos.ToArray();
foreach (var instance in instances)
{
if (output.Length == 0)
{
for (int i = 0; i < properties.Length - 1; i++)
{
output.Append(properties[i].Name);
if (i != properties.Length - 1)
output.Append(", ");
}
output.AppendLine();
}
for (int i = 0; i < properties.Length - 1; i++)
{
output.Append(properties[i].GetValue(instance, null));
if (i != properties.Length - 1)
output.Append(", ");
}
output.AppendLine();
}
Console.WriteLine(output.ToString());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment