Created
September 30, 2011 04:50
-
-
Save msbukkuri/1252697 to your computer and use it in GitHub Desktop.
CsvPrinter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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