/Rhino.Etl.Core/DataReaders/DictionaryEnumeratorDataReader.cs

http://github.com/ayende/rhino-etl · C# · 55 lines · 34 code · 5 blank · 16 comment · 4 complexity · 41e0844bb0662480b5545c86b9987eb9 MD5 · raw file

  1. namespace Rhino.Etl.Core.DataReaders
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. /// <summary>
  6. /// A datareader over a collection of dictionaries
  7. /// </summary>
  8. public class DictionaryEnumeratorDataReader : EnumerableDataReader
  9. {
  10. private readonly IEnumerable<Row> enumerable;
  11. private readonly List<Descriptor> propertyDescriptors = new List<Descriptor>();
  12. /// <summary>
  13. /// Initializes a new instance of the <see cref="DictionaryEnumeratorDataReader"/> class.
  14. /// </summary>
  15. /// <param name="schema">The schema.</param>
  16. /// <param name="enumerable">The enumerator.</param>
  17. public DictionaryEnumeratorDataReader(
  18. IDictionary<string, Type> schema,
  19. IEnumerable<Row> enumerable)
  20. : base(enumerable.GetEnumerator())
  21. {
  22. this.enumerable = enumerable;
  23. foreach (KeyValuePair<string, Type> pair in schema)
  24. {
  25. propertyDescriptors.Add(new DictionaryDescriptorAdapter(pair));
  26. }
  27. }
  28. /// <summary>
  29. /// Gets the descriptors for the properties that this instance
  30. /// is going to handle
  31. /// </summary>
  32. /// <value>The property descriptors.</value>
  33. protected override IList<Descriptor> PropertyDescriptors
  34. {
  35. get { return propertyDescriptors; }
  36. }
  37. /// <summary>
  38. /// Perform the actual closing of the reader
  39. /// </summary>
  40. protected override void DoClose()
  41. {
  42. IDisposable disposable = enumerator as IDisposable;
  43. if (disposable != null)
  44. disposable.Dispose();
  45. disposable = enumerable as IDisposable;
  46. if(disposable != null)
  47. disposable.Dispose();
  48. }
  49. }
  50. }