@@ -32,6 +32,8 @@ public class NDataReader : DbDataReader
32
32
private char [ ] cachedCharArray ;
33
33
private int cachedColIndex = - 1 ;
34
34
35
+ protected NDataReader ( ) { }
36
+
35
37
/// <summary>
36
38
/// Creates a NDataReader from a <see cref="DbDataReader" />
37
39
/// </summary>
@@ -43,8 +45,9 @@ public class NDataReader : DbDataReader
43
45
/// pick up the <see cref="DbDataReader"/> midstream so that the underlying <see cref="DbDataReader"/> can be closed
44
46
/// so a new one can be opened.
45
47
/// </remarks>
46
- public NDataReader Initialize ( DbDataReader reader , bool isMidstream )
48
+ public static NDataReader Create ( DbDataReader reader , bool isMidstream )
47
49
{
50
+ var dataReader = new NDataReader ( ) ;
48
51
var resultList = new List < NResult > ( 2 ) ;
49
52
50
53
try
@@ -53,19 +56,19 @@ public NDataReader Initialize(DbDataReader reader, bool isMidstream)
53
56
// positioned on the first row (index=0)
54
57
if ( isMidstream )
55
58
{
56
- currentRowIndex = 0 ;
59
+ dataReader . currentRowIndex = 0 ;
57
60
}
58
61
59
62
// there will be atleast one result
60
- resultList . Add ( new NResult ( ) . Initialize ( reader , isMidstream ) ) ;
63
+ resultList . Add ( NResult . Create ( reader , isMidstream ) ) ;
61
64
62
65
while ( reader . NextResult ( ) )
63
66
{
64
67
// the second, third, nth result is not processed midstream
65
- resultList . Add ( new NResult ( ) . Initialize ( reader , false ) ) ;
68
+ resultList . Add ( NResult . Create ( reader , false ) ) ;
66
69
}
67
70
68
- results = resultList . ToArray ( ) ;
71
+ dataReader . results = resultList . ToArray ( ) ;
69
72
}
70
73
catch ( Exception e )
71
74
{
@@ -75,7 +78,7 @@ public NDataReader Initialize(DbDataReader reader, bool isMidstream)
75
78
{
76
79
reader . Close ( ) ;
77
80
}
78
- return this ;
81
+ return dataReader ;
79
82
}
80
83
81
84
/// <summary>
@@ -476,6 +479,8 @@ private class NResult
476
479
private readonly IList < System . Type > fieldTypes = new List < System . Type > ( ) ;
477
480
private readonly IList < string > fieldDataTypeNames = new List < string > ( ) ;
478
481
482
+ private NResult ( ) { }
483
+
479
484
/// <summary>
480
485
/// Initializes a new instance of the NResult class.
481
486
/// </summary>
@@ -484,9 +489,12 @@ private class NResult
484
489
/// <see langword="true" /> if the <see cref="DbDataReader"/> is already positioned on the record
485
490
/// to start reading from.
486
491
/// </param>
487
- internal NResult Initialize ( DbDataReader reader , bool isMidstream )
492
+ internal static NResult Create ( DbDataReader reader , bool isMidstream )
488
493
{
489
- schemaTable = reader . GetSchemaTable ( ) ;
494
+ var result = new NResult
495
+ {
496
+ schemaTable = reader . GetSchemaTable ( )
497
+ } ;
490
498
491
499
List < object [ ] > recordsList = new List < object [ ] > ( ) ;
492
500
int rowIndex = 0 ;
@@ -500,13 +508,13 @@ internal NResult Initialize(DbDataReader reader, bool isMidstream)
500
508
for ( int i = 0 ; i < reader . FieldCount ; i ++ )
501
509
{
502
510
string fieldName = reader . GetName ( i ) ;
503
- fieldNameToIndex [ fieldName ] = i ;
504
- fieldIndexToName . Add ( fieldName ) ;
505
- fieldTypes . Add ( reader . GetFieldType ( i ) ) ;
506
- fieldDataTypeNames . Add ( reader . GetDataTypeName ( i ) ) ;
511
+ result . fieldNameToIndex [ fieldName ] = i ;
512
+ result . fieldIndexToName . Add ( fieldName ) ;
513
+ result . fieldTypes . Add ( reader . GetFieldType ( i ) ) ;
514
+ result . fieldDataTypeNames . Add ( reader . GetDataTypeName ( i ) ) ;
507
515
}
508
516
509
- colCount = reader . FieldCount ;
517
+ result . colCount = reader . FieldCount ;
510
518
}
511
519
512
520
rowIndex ++ ;
@@ -520,8 +528,8 @@ internal NResult Initialize(DbDataReader reader, bool isMidstream)
520
528
isMidstream = false ;
521
529
}
522
530
523
- records = recordsList . ToArray ( ) ;
524
- return this ;
531
+ result . records = recordsList . ToArray ( ) ;
532
+ return result ;
525
533
}
526
534
527
535
/// <summary>
0 commit comments