PageRenderTime 203ms CodeModel.GetById 121ms app.highlight 3ms RepoModel.GetById 77ms app.codeStats 0ms

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