@@ -16,9 +16,9 @@ namespace BulkOperations
16
16
public class ObjectDataReader < T > : DbDataReader
17
17
{
18
18
private readonly IEnumerator < T > _iterator ;
19
- private readonly IDictionary < string , int > _propertyNameToOrdinal = new Dictionary < string , int > ( ) ;
20
- private readonly IDictionary < int , string > _ordinalToPropertyName = new Dictionary < int , string > ( ) ;
21
- private Func < T , object > [ ] _getPropertyValueFuncs ;
19
+ private readonly IDictionary < string , int > _propToOrdinalTable = new Dictionary < string , int > ( ) ;
20
+ private readonly IDictionary < int , string > _ordinalToPropTable = new Dictionary < int , string > ( ) ;
21
+ private Func < T , object > [ ] _getPropValueFunc ;
22
22
23
23
public ObjectDataReader ( IEnumerator < T > items )
24
24
{
@@ -29,14 +29,14 @@ public ObjectDataReader(IEnumerator<T> items)
29
29
private void Initialize ( )
30
30
{
31
31
var properties = typeof ( T ) . GetProperties ( ) ;
32
- _getPropertyValueFuncs = new Func < T , object > [ properties . Length ] ;
32
+ _getPropValueFunc = new Func < T , object > [ properties . Length ] ;
33
33
34
34
var ordinal = 0 ;
35
35
foreach ( var property in properties )
36
36
{
37
37
var propertyName = property . Name ;
38
- _propertyNameToOrdinal . Add ( propertyName , ordinal ) ;
39
- _ordinalToPropertyName . Add ( ordinal , propertyName ) ;
38
+ _propToOrdinalTable . Add ( propertyName , ordinal ) ;
39
+ _ordinalToPropTable . Add ( ordinal , propertyName ) ;
40
40
41
41
var parameterExpression = Expression . Parameter ( typeof ( T ) , "x" ) ;
42
42
var func = ( Func < T , object > ) Expression . Lambda (
@@ -46,7 +46,7 @@ private void Initialize()
46
46
parameterExpression )
47
47
. Compile ( ) ;
48
48
49
- _getPropertyValueFuncs [ ordinal ] = func ;
49
+ _getPropValueFunc [ ordinal ] = func ;
50
50
51
51
ordinal ++ ;
52
52
}
@@ -60,7 +60,7 @@ public override bool Read()
60
60
61
61
public override int GetOrdinal ( string name )
62
62
{
63
- return ( _propertyNameToOrdinal . TryGetValue ( name , out var ordinal ) ) ? ordinal : - 1 ;
63
+ return ( _propToOrdinalTable . TryGetValue ( name , out var ordinal ) ) ? ordinal : - 1 ;
64
64
}
65
65
66
66
public override bool IsDBNull ( int ordinal )
@@ -70,11 +70,10 @@ public override bool IsDBNull(int ordinal)
70
70
71
71
public override object GetValue ( int ordinal )
72
72
{
73
- var func = _getPropertyValueFuncs [ ordinal ] ;
73
+ var func = _getPropValueFunc [ ordinal ] ;
74
74
return func ( _iterator . Current ) ;
75
75
}
76
76
77
- // optional
78
77
public override int GetValues ( object [ ] values )
79
78
{
80
79
var max = Math . Min ( values . Length , FieldCount ) ;
@@ -92,13 +91,12 @@ public override int GetValues(object[] values)
92
91
93
92
public override int Depth => 0 ;
94
93
95
- public override int FieldCount => _ordinalToPropertyName . Count ;
94
+ public override int FieldCount => _ordinalToPropTable . Count ;
96
95
97
96
public override bool HasRows => true ;
98
97
99
98
public override bool IsClosed => _iterator != null ;
100
99
101
- public override int RecordsAffected => throw new NotImplementedException ( ) ;
102
100
103
101
public override bool GetBoolean ( int ordinal )
104
102
{
@@ -110,26 +108,11 @@ public override byte GetByte(int ordinal)
110
108
return ( byte ) GetValue ( ordinal ) ;
111
109
}
112
110
113
- public override long GetBytes ( int ordinal , long dataOffset , byte [ ] buffer , int bufferOffset , int length )
114
- {
115
- throw new NotImplementedException ( ) ;
116
- }
117
-
118
111
public override char GetChar ( int ordinal )
119
112
{
120
113
return ( char ) GetValue ( ordinal ) ;
121
114
}
122
115
123
- public override long GetChars ( int ordinal , long dataOffset , char [ ] buffer , int bufferOffset , int length )
124
- {
125
- throw new NotImplementedException ( ) ;
126
- }
127
-
128
- public override string GetDataTypeName ( int ordinal )
129
- {
130
- throw new NotImplementedException ( ) ;
131
- }
132
-
133
116
public override DateTime GetDateTime ( int ordinal )
134
117
{
135
118
return ( DateTime ) GetValue ( ordinal ) ;
@@ -145,11 +128,6 @@ public override double GetDouble(int ordinal)
145
128
return ( double ) GetValue ( ordinal ) ;
146
129
}
147
130
148
- public override IEnumerator GetEnumerator ( )
149
- {
150
- throw new NotImplementedException ( ) ;
151
- }
152
-
153
131
public override Type GetFieldType ( int ordinal )
154
132
{
155
133
var value = GetValue ( ordinal ) ;
@@ -183,7 +161,7 @@ public override long GetInt64(int ordinal)
183
161
184
162
public override string GetName ( int ordinal )
185
163
{
186
- return _ordinalToPropertyName . TryGetValue ( ordinal , out var name ) ? name : null ;
164
+ return _ordinalToPropTable . TryGetValue ( ordinal , out var name ) ? name : null ;
187
165
}
188
166
189
167
public override string GetString ( int ordinal )
@@ -195,5 +173,30 @@ public override bool NextResult()
195
173
{
196
174
return false ;
197
175
}
176
+
177
+ #region NotImplemented
178
+ public override int RecordsAffected =>
179
+ throw new NotImplementedException ( ) ;
180
+
181
+ public override long GetBytes ( int ordinal , long dataOffset , byte [ ] buffer , int bufferOffset , int length )
182
+ {
183
+ throw new NotImplementedException ( ) ;
184
+ }
185
+
186
+ public override long GetChars ( int ordinal , long dataOffset , char [ ] buffer , int bufferOffset , int length )
187
+ {
188
+ throw new NotImplementedException ( ) ;
189
+ }
190
+
191
+ public override string GetDataTypeName ( int ordinal )
192
+ {
193
+ throw new NotImplementedException ( ) ;
194
+ }
195
+
196
+ public override IEnumerator GetEnumerator ( )
197
+ {
198
+ throw new NotImplementedException ( ) ;
199
+ }
200
+ #endregion
198
201
}
199
202
}
0 commit comments