PageRenderTime 41ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/Sources/DataAccess/EnumerableDataTable.cs

https://github.com/tpwalke2/DataTable
C# | 43 lines | 35 code | 5 blank | 3 comment | 0 complexity | 2f08508a7b520dd1d51e2eb7d21dcac7 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.IO;
  5. using System.Diagnostics;
  6. using System.Text.RegularExpressions;
  7. using System.Linq;
  8. namespace DataAccess
  9. {
  10. /// <summary>
  11. /// Create a streaming data table around an Ienumerable
  12. /// </summary>
  13. internal class EnumerableDataTable<T> : DataTable
  14. {
  15. private readonly IEnumerable<T> _source;
  16. private readonly string[] _columnNames;
  17. public EnumerableDataTable(IEnumerable<T> source)
  18. {
  19. _source = source;
  20. _columnNames = Utility.InferColumnNames<T>();
  21. }
  22. public override IEnumerable<string> ColumnNames
  23. {
  24. get { return _columnNames; }
  25. }
  26. public override IEnumerable<Row> Rows
  27. {
  28. get
  29. {
  30. foreach (T item in _source)
  31. {
  32. string[] values = Utility.Flatten<T>(item);
  33. yield return new RowFromStreamingTable(values, this);
  34. }
  35. }
  36. }
  37. }
  38. }