-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMultiDataReader.cs
More file actions
50 lines (43 loc) · 1.21 KB
/
Copy pathMultiDataReader.cs
File metadata and controls
50 lines (43 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using DataBoss.Linq;
namespace DataBoss.Data
{
public class MultiDataReader : DataReaderDecoratorBase
{
readonly IReadOnlyList<DbDataReader> readers;
readonly int[] nextNext;
int next;
public MultiDataReader(IReadOnlyList<DbDataReader> readers) : base(readers[0]) {
this.readers = readers;
this.nextNext = new int[readers.Count];
for(var i = 0; i != readers.Count; ++i)
this.nextNext[i] = (i + 1) % readers.Count;
this.next = readers.Count - 1;
}
public override bool IsClosed => readers.All(x => x.IsClosed);
public override void Close() => readers.ForEach(x => x.Close());
protected override void Dispose(bool disposing)
{
if(!disposing)
return;
readers.ForEach(x => x.Dispose());
}
public override bool NextResult() => false;
public override bool Read() {
for(;;) {
var current = nextNext[next];
if (readers[current].Read()) {
Inner = readers[current];
next = current;
return true;
} else {
if(current == nextNext[current])
return false;
nextNext[next] = nextNext[current];
}
}
}
}
}