List of ExpandoObjects in Util.WriteCsv

Hi Joe,

The latest version handles ExpandoObjects well with Dump, which is sweet as I had to do a nasty select with them to get the proper results before. However what works well with Dump still does not work well with Util.WriteCsv. The result is this:

Any ideas how to get the same output as Dump?




  • edited March 29
    I was hoping for an answer to this question as well.

    In the end I just wrote my own, so for anyone looking for this, just cast your ExpandoObjects to IDictionary and pass the list:
    private void WriteLine(StreamWriter outputFile, IEnumerable items) { var first = true; foreach (var item in items) { if (!first) outputFile.Write(","); if (null != item) outputFile.Write(item); else outputFile.Write(string.Empty); first = false; } outputFile.WriteLine(); } public void WriteCsv(IList> results, string outputFilePath) { using (var outputFile = new StreamWriter(outputFilePath)) { // First write the headers WriteLine(outputFile, results.First().Keys); // Now write the data rows foreach (var result in results) { WriteLine(outputFile, result.Values.Select(v => v.ToString())); } } }
  • Good call - I'll fix this for the next build.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!