Skip to content

Instantly share code, notes, and snippets.

@SuperYeti
Created July 13, 2011 03:24
Show Gist options
  • Select an option

  • Save SuperYeti/1079650 to your computer and use it in GitHub Desktop.

Select an option

Save SuperYeti/1079650 to your computer and use it in GitHub Desktop.
public static string ToCsv<T>(string separator, IEnumerable<T> objectlist)
{
Type t = typeof(T);
FieldInfo[] fields = t.GetFields();
string header = String.Join(separator, fields.Select(f => f.Name).ToArray());
StringBuilder csvdata = new StringBuilder();
csvdata.AppendLine(header);
foreach (var o in objectlist)
csvdata.AppendLine(ToCsvFields(separator, fields, o));
return csvdata.ToString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment